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(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(cors({ origin: [process.env.FRONTEND_URL, 'http://localhost:3000'], credentials: true }));
//--------------------
// Cookies settings
const cookieSettings = {
httpOnly: true,
secure: IS_PRODUCTION,
};
//--------------------
// Sessions
const KnexSessionStore = connectSessionKnex(session);
const store = new KnexSessionStore({ knex });
app.use(
session({
cookie: cookieSettings,
secret: 'test',
resave: false,
saveUninitialized: false,
store,
})
);
//--------------------
// Auth
app.use(auth({ cookieSettings }));
import express from 'express'
import bodyParser from 'body-parser'
import path from 'path'
import morgan from 'morgan'
import Debug from 'debug'
import session from 'express-session'
import KnexSessionStore from 'connect-session-knex'
import db from './controllers/config/knex'
import devOptions from './controllers/config/dev.serv.opt'
import history from 'connect-history-api-fallback'
import serveStatic from 'serve-static'
// routes
import auth from './routes/auth'
const SessionStore = KnexSessionStore(session)
const store = new SessionStore({
knex: db,
tablename: 'session'
})
const debug = Debug('server:app')
const port = process.env.PORT || 5000
const app = express()
app.use(bodyParser.json())
app.use(morgan('dev'))
app.use(history())
app.use(session({
secret: 'secret',
saveUninitialized: true,
resave: true,
store: store