generated from AgathePons/Base-Express-EJS-Session-pg-SASS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (29 loc) · 842 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require('dotenv').config();
const express = require('express');
const session = require('express-session');
const userMiddleware = require('./app/middlewares/user');
const router = require('./app/router');
const PORT = process.env.PORT || 3000;
const app = express();
app.set('views', './app/views');
app.set('view engine', 'ejs');
app.use(express.static('public'));
app.use(express.urlencoded({extended: true}));
app.use(session({
// doc express-session : npmjs.com/package/express-session
secret: process.env.SECRET_KEY,
resave: true,
saveUninitialized: true,
cookie : {
secure: false,
maxAge: (1000*60*60) // ça fait une heure
}
}));
app.use(userMiddleware);
app.use(router);
app.use((req, res) => {
res.status(404).render('notFound');
});
app.listen(PORT, () => {
console.log(`Listening on ${PORT}`);
});