Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
app.use(compress());
app.use(methodOverride());
app.use(passport.initialize());
app.use(passport.session());
// disable 'X-Powered-By' header in response
app.disable('x-powered-by');
// enable CORS - Cross Origin Resource Sharing
app.use(cors());
// enable detailed API logging in dev env
if (config.env === 'development') {
expressWinston.requestWhitelist.push('body');
expressWinston.responseWhitelist.push('body');
app.use(expressWinston.logger({
winstonInstance,
meta: true, // optional: log meta data about request (defaults to true)
msg: 'HTTP {{req.method}} {{req.url}} {{res.statusCode}} {{res.responseTime}}ms',
colorStatus: true // Color the status code (default green, 3XX cyan, 4XX yellow, 5XX red).
}));
}
if (config.staticPath) {
/* eslint-disable no-console */
console.log('Serve static files from: \x1b[36m' + config.staticPath + '\x1b[0m');
/* eslint-enable no-console */
app.use(express.static(config.staticPath));
}
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(compress());
app.use(methodOverride());
// secure apps by setting various HTTP headers
app.use(helmet());
// enable CORS - Cross Origin Resource Sharing
app.use(cors());
// enable detailed API logging in dev env
if (config.env === 'development') {
expressWinston.requestWhitelist.push('body');
expressWinston.responseWhitelist.push('body');
// app.use(expressWinston.logger({
// winstonInstance,
// meta: true, // optional: log meta data about request (defaults to true)
// msg: 'HTTP {{req.method}} {{req.url}} {{res.statusCode}} {{res.responseTime}}ms',
// colorStatus: true // Color the status code (default green, 3XX cyan, 4XX yellow, 5XX red).
// }));
}
app.use(express.static(path.join(appRoot.path, 'dist')));
app.use('/api', routes);
innograph.init('/api/graphql', app, {post: postCtrl});
app.get('*', (req, res) => {
res.sendFile(path.join(appRoot.path, 'dist/index.html'));
});
app.use(morgan('dev'))
}
app.use(bodyParser.urlencoded({ extended: true, }))
app.use(bodyParser.json())
app.use(compression())
app.use(cookieParser())
app.use(cors())
app.use(helmet())
app.use(methodOverride())
// enable detailed API logging in all env except test
if (env.NODE_ENV !== 'test') {
expressWinston.requestWhitelist.push('body')
expressWinston.responseWhitelist.push('body')
app.use(expressWinston.logger({
winstonInstance,
meta: true, // optional: log meta data about request (defaults to true)
msg: 'HTTP {{req.method}} {{req.url}} {{res.statusCode}} {{res.responseTime}}ms',
colorStatus: true, // Color the status code (default green, 3XX cyan, 4XX yellow, 5XX red).
}))
}
/**
* @apiDescription Mounts api routes at /api
* @apiGroup API
*/
app.use('/api', routes)
// catch 404 and forward to error handler
app.use((req, res, next) => {
app.use(compress());
app.use(methodOverride());
// secure apps by setting various HTTP headers
app.use(helmet());
// enable CORS - Cross Origin Resource Sharing
app.use(cors());
// This is really just a test output and should be the first thing you see
winstonInstance.info('The application is starting...');
// enable detailed API logging in dev env
if (config.env === 'development') {
expressWinston.requestWhitelist.push('body');
expressWinston.responseWhitelist.push('body');
app.use(expressWinston.logger({
winstonInstance,
meta: true, // optional: log meta data about request (defaults to true)
msg: 'HTTP {{req.method}} {{req.url}} {{res.statusCode}} {{res.responseTime}}ms',
colorStatus: true, // Color the status code (default green, 3XX cyan, 4XX yellow, 5XX red).
}));
}
// Get API Version from .env (or else assume 1.0)
const baseUrl = `/api/v${config.apiVersion}`;
// mount all routes on /api path
app.use(`${baseUrl}`, routes);
// if error is not an instanceOf APIError, convert it.
app.use((err, req, res, next) => {
// origin: [], // TODO add origins for production
// optionsSuccessStatus: 200
// }))
// Enable Forest Admin (must be done before express error handlers)
} else {
app.use(cors())
}
// Load Forest Admin (must be after CORS)
require('config/forestadmin')(app)
// Enable detailed API logging
if (env.NODE_ENV !== env.Environments.Test) {
expressWinston.requestWhitelist.push('body')
expressWinston.responseWhitelist.push('body')
app.use(expressWinston.logger({
winstonInstance: logger,
meta: true, // optional: log meta data about request (defaults to true)
msg: 'HTTP {{req.method}} {{req.url}} {{res.statusCode}} {{res.responseTime}}ms',
colorStatus: true, // Color the status code (default green, 3XX cyan, 4XX yellow, 5XX red).
skip: (req, res) => {
// Filter logging errors here that are not really errors. This also prevents them from showing up in Sentry.
// Filter 404: bots cause these
if (env.NODE_ENV === env.Environments.Production) {
return (
res.statusCode === httpStatus.NOT_FOUND
||
(res.statusCode === httpStatus.OK && req.url.includes('/misc/health-check'))
)
}
export default app => {
app.use(function onError(err, req, res, next) {
res.statusCode = 500;
res.end(res.sentry + '\n');
});
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cors());
if (isDev && !isTest) {
app.use(morgan('dev'));
expressWinston.requestWhitelist.push('body');
expressWinston.responseWhitelist.push('body');
// app.use(
// expressWinston.logger({
// winstonInstance,
// meta: true,
// msg:
// 'HTTP {{req.method}} {{req.url}} {{res.statusCode}} {{res.responseTime}}ms',
// colorStatus: true,
// }),
// );
}
};
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(compress());
app.use(methodOverride());
// secure apps by setting various HTTP headers
app.use(helmet());
// enable CORS - Cross Origin Resource Sharing
app.use(cors());
// enable detailed API logging in dev env
if (config.env === 'development') {
expressWinston.requestWhitelist.push('body');
expressWinston.responseWhitelist.push('body');
app.use(expressWinston.logger({
winstonInstance,
meta: true, // optional: log meta data about request (defaults to true)
msg: 'HTTP {{req.method}} {{req.url}} {{res.statusCode}} {{res.responseTime}}ms',
colorStatus: true // Color the status code (default green, 3XX cyan, 4XX yellow, 5XX red).
}));
}
// mount all routes on /api path
app.use('/repairnator-mongo-api', routes);
// if error is not an instanceOf APIError, convert it.
app.use((err, req, res, next) => {
if (err instanceof expressValidation.ValidationError) {
// validation error contains errors which is an array of error each containing message[]
const unifiedErrorMessage = err.errors.map(error => error.messages.join('. ')).join(' and ');
}
}),
);
// must be right after bodyParser
app.use(expressValidator());
app.use(
busboy({
limits: {
fileSize: 5242880,
},
}),
);
app.use(hpp());
if (process.env.NODE_ENV !== 'production') {
expressWinston.requestWhitelist.push('body');
expressWinston.responseWhitelist.push('body');
app.use(
expressWinston.logger({
winstonInstance,
meta: true,
msg: 'HTTP {{req.method}} {{req.url}} {{res.statusCode}} {{res.responseTime}}ms',
colorStatus: true,
}),
);
}
app.use(flash());
};
export default app => {
app.use(compression())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
app.use(passport.initialize())
app.use(cors({
credentials: true,
origin: process.env.FRONT_ORIGIN // Change allowed origin url for production
}))
app.use(methodOverride())
if (isDev && !isTest) {
app.use(morgan('dev'))
expressWinston.requestWhitelist.push('body')
expressWinston.responseWhitelist.push('body')
app.use(
expressWinston.logger({
winstonInstance,
meta: true,
msg:
'HTTP {{req.method}} {{req.url}} {{res.statusCode}} {{res.responseTime}}ms',
colorStatus: true
}),
)
}
}
export default app => {
app.use(compression());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(passport.initialize());
app.use(helmet());
app.use(cors(corsWhiteList));
app.use(methodOverride());
if (isDev && !isTest) {
app.use(morgan('dev'));
expressWinston.requestWhitelist.push('body');
expressWinston.responseWhitelist.push('body');
app.use(
expressWinston.logger({
winstonInstance,
meta: true,
msg:
'HTTP {{req.method}} {{req.url}} {{res.statusCode}} {{res.responseTime}}ms',
colorStatus: true,
}),
);
}
};