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(
morgan(
'[:date[iso]] :date[web] :remote-addr - :remote-user :method :url :status[pretty] :response-time',
),
);
const sessionOptions = {
resave: true,
saveUninitialized: true,
secret: process.env.RANDOM_TOKEN,
};
if (process.env.NODE_ENV === 'production') {
const database = process.env.NODE_ENV === 'test' ? 'test' : 'coding-coach';
const dbURI = process.env.MONGO_DB_URI || `mongodb://localhost/${database}`;
const MongoDBStore = MongoDBSession(session);
const store = new MongoDBStore({
uri: dbURI,
collection: 'app_sessions',
});
sessionOptions.store = store;
}
app.use(session(sessionOptions));
app.use(cors());
oauthInitialize(app);
routes(app);
export default app;
import express from 'express';
import mongoose from 'mongoose';
import cors from 'cors';
import session from 'express-session';
import connectMongoDBSession from 'connect-mongodb-session';
import passport from 'passport';
import cookieParser from 'cookie-parser';
import authRoutes from './routes/auth';
import { isUser } from './middleware/auth-middleware';
import User from './models/user';
const app = express();
const MongoDBStore = connectMongoDBSession(session);
const store = new MongoDBStore({
uri: process.env.MONGODB_URI,
collection: 'sessions'
});
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser(process.env.SECRET));
app.use(
session({
secret: process.env.SECRET,
resave: false,
saveUninitialized: false,