Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function (expressApp) {
if ((!env.FOREST_AUTH_SECRET || !env.FOREST_ENV_SECRET) && env.NODE_ENV !== env.Environments.Test) {
console.log('Forest Admin:\t\tMissing credentials, not loading')
return
}
if (env.NODE_ENV === env.Environments.Test) {
// console.log('Forest Admin: Not loading outside production environment')
} else {
expressApp.use(require('forest-express-mongoose').init({
envSecret: env.FOREST_ENV_SECRET,
authSecret: env.FOREST_AUTH_SECRET,
mongoose: require('mongoose')
}))
// require('./forest/actions/user')
console.log('Forest Admin:\t\tLoaded')
}
}
}));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(expressValidator());
app.use(session({
resave: true,
saveUninitialized: true,
secret: process.env.SESSION_SECRET,
cookie: { maxAge: 1209600000 }, // two weeks in milliseconds
store: new MongoStore({
url: process.env.MONGODB_URI,
autoReconnect: true,
})
}));
app.use(require('forest-express-mongoose').init({
modelsDir: __dirname + '/models',
envSecret: process.env.FOREST_ENV_SECRET,
authSecret: process.env.FOREST_AUTH_SECRET,
mongoose: require('mongoose')
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
app.use((req, res, next) => {
lusca.csrf()(req, res, next);
});
app.use(lusca.xframe('SAMEORIGIN'));
app.use(lusca.xssProtection(true));
app.disable('x-powered-by');
app.use((req, res, next) => {
res.locals.user = req.user;