import { raw } from 'body-parser' ; import * as express from 'express' ; import Clova from './types' ; import verifier from './verifier' ; export default function verifierMiddleware ( config ) { return ( req , res , next ) => { const signature = req . headers . signaturecek as string ; const { applicationId } = config ; const process = async ( rawBody ) => { const body = Buffer . isBuffer ( rawBody ) ? rawBody . toString ( ) : rawBody ; try { req . body = await verifier ( signature , applicationId , body ) ; next ( ) ; } catch ( error ) { next ( error ) ; } } ; if ( typeof req . body === 'string' || Buffer . isBuffer ( req . body ) ) { return process ( req . body ) ; } raw ( { type : '*/*' } ) ( req as any , res as any , async ( ) => await process ( req . body ) ) ; } ; }