Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const create = config => {
// Server settings
server.set('env', config.env);
server.set('port', config.server.port);
server.set('hostname', config.server.hostname);
// Returns middleware that parses json
server.use(json());
server.use(urlencoded({ extended: true }));
morganBody(server, {
stream: winston.stream,
});
server.use(
cookieSession({
maxAge: 30 * 24 * 60 * 60 * 1000,
keys: [keys.server.cookieKey],
}),
);
server.use(cookieParser(keys.server.cookieKey));
server.use(passport.initialize());
server.use(passport.session());
// Set up routes
server.use('/api/plex', plex);
server.use('/api/tdaw', tdaw);
module.exports = (config) => {
if (!config || !config.db) {
throw new Error('Missing or malformed config');
}
const version = config.api_version || API_VERSION;
db(config.db);
let router = express.Router();
if (process.env.NODE_DEBUG === 'morgan') {
logger(router);
}
router.use('/' + version + '/', baseRouter);
const routeExpr = route.generate(version);
router.use(routeExpr, associations(version));
router.use(routeExpr, queryParser);
Object.keys(entities).forEach(endpoint => {
router.use(route.generate(version, endpoint),
require('./routes/' + snake(endpoint))(version));
});
router.use('/' + version + '/' + createObservations,
dataArrayRouter(version));
return router;