import * as express from 'express' ; import * as bodyParser from 'body-parser' ; import * as cookieParser from 'cookie-parser' ; import * as helmet from 'helmet' ; import * as csrf from 'csurf' ; param app export const secureApp = ( app ) => { app . use ( bodyParser . json ( { limit : '50mb' } ) ) ; app . use ( bodyParser . urlencoded ( { limit : '50mb' , extended : true , parameterLimit : 50000 } ) ) ; app . use ( helmet ( ) ) ; app . use ( cookieParser ( process . env . SESSION_SECRET ) ) ; app . use ( bodyParser . urlencoded ( { extended : true } ) ) ; if ( process . env . NODE_ENV === 'production' && process . env . CORS === 'true' ) { app . use ( csrf ( { cookie : true } ) ) ; } app . use ( ( req , res , next ) => { if ( process . env . NODE_ENV === 'production' && process . env . CORS === 'true' ) { res . cookie ( 'XSRF-TOKEN' , req . csrfToken ( ) ) ; } next ( ) ; } ) ; } ;