Skip to content
This repository has been archived by the owner on Dec 31, 2020. It is now read-only.

Commit

Permalink
added in express middleware to handle session (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhuang612 authored and Asjas committed Dec 18, 2019
1 parent 6c04b59 commit dc946e2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"test:server:functional": "babel-tape-runner -r dotenv/config server/tests/**/*.func.js | node_modules/.bin/tap-spec",
"test:client": "mocha --require tools/testClientSetup.js tools/testSetup.js \"client/**/*.spec.js\"",
"test": "npm run test:client && npm run test:server",
"updateDB":"node_modules/.bin/sequelize db:migrate --env production"
"updateDB": "node_modules/.bin/sequelize db:migrate --env production"
},
"repository": {
"type": "git",
Expand All @@ -49,6 +49,7 @@
"connect-history-api-fallback": "^1.3.0",
"connect-redis": "^3.3.0",
"cookie-parser": "^1.4.3",
"cookie-session": "^1.3.3",
"csv": "^1.1.0",
"debug": "^2.6.8",
"dompurify": "^0.9.0",
Expand Down
15 changes: 9 additions & 6 deletions server/config/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require('path');
const express = require('express');
const passport = require('passport');
const helmet = require('helmet');

const cookieSession = require('cookie-session');
const configureSequelize = require('./sequelize');
const configureWebpackDevMiddleware = require('./webpack-dev-middleware');
const configureRedis = require('./redis');
Expand All @@ -23,11 +23,7 @@ module.exports = () => {
configureWebpackDevMiddleware(app);

// Configure redis, receiving connections to client, subscriber and publisher
const {
client,
subscriber,
publisher,
} = configureRedis();
const { client, subscriber, publisher } = configureRedis();

// Configure session handling with redis, through the client connection.
const { sessionMiddleware } = configureSession(client);
Expand All @@ -42,6 +38,13 @@ module.exports = () => {
app.use(passport.session()); // Use passport middleware for auth
app.use(helmet()); // Implements various security tweaks to http response headers

app.use(
cookieSession({
maxAge: 30 * 24 * 60 * 60 * 1000,
keys: [process.env.COOKIE_SESSION]
})
);

app.use('/public', express.static(path.join(__dirname, '../../../public'))); // Serve /public static files when unauth
app.use('/dist', express.static(path.join(__dirname, '../../../dist'))); // Serve /dist static diles when auth

Expand Down

0 comments on commit dc946e2

Please sign in to comment.