UNPKG

2.02 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.useSign = useSign;
7
8var _bodyParser = require('body-parser');
9
10var _bodyParser2 = _interopRequireDefault(_bodyParser);
11
12var _compression = require('compression');
13
14var _compression2 = _interopRequireDefault(_compression);
15
16var _cookieParser = require('cookie-parser');
17
18var _cookieParser2 = _interopRequireDefault(_cookieParser);
19
20var _connectFlash = require('connect-flash');
21
22var _connectFlash2 = _interopRequireDefault(_connectFlash);
23
24var _expressSession = require('express-session');
25
26var _expressSession2 = _interopRequireDefault(_expressSession);
27
28var _passport = require('passport');
29
30var _passport2 = _interopRequireDefault(_passport);
31
32function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33
34var MongoStore = require('connect-mongo')(_expressSession2.default);
35function useSign(app, config) {
36 // unpack
37 var db = config.db,
38 isProd = config.isProd,
39 _config$session = config.session,
40 expiry = _config$session.expiry,
41 key = _config$session.key,
42 secret = _config$session.secret;
43 // store
44
45 var store = new MongoStore({
46 db: db,
47 ttl: expiry
48 });
49 // set up sessions, requires for auth (via passport)
50 var sess = {
51 cookie: { maxAge: expiry },
52 key: key,
53 secret: secret,
54 store: store,
55 resave: false,
56 saveUninitialized: false
57 };
58 if (isProd) {
59 app.set('trust proxy', 1);
60 sess.cookie.secure = true;
61 }
62 // use
63 app.use((0, _cookieParser2.default)('keyboard cat')); // read cookies - needed for flash messages
64 app.use((0, _connectFlash2.default)()); // flash messages, used for login/signup errors
65 app.use(_bodyParser2.default.urlencoded({ extended: true }));
66 app.use(_bodyParser2.default.json());
67 app.use((0, _expressSession2.default)(sess));
68 app.use(_passport2.default.initialize());
69 app.use(_passport2.default.session()); // persistent login sessions
70 app.use((0, _compression2.default)());
71}
\No newline at end of file