forked from rgserrano/todo-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (39 loc) · 1.09 KB
/
app.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
39
40
41
42
43
44
const express = require('express');
const apiRouter = require("./routes/api")
const morgan = require('morgan');
const session = require('express-session');
const store = require('connect-loki');
const app = express();
const LokiStore = store(session);
const Todo = require("./lib/todo");
app.set('port', process.env.PORT || 3000);
app.use(morgan("dev"));
app.use(express.static("public"));
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use(session({
cookie: {
httpOnly: true,
maxAge: 31 * 24 * 60 * 60 * 1000,
path: "/",
secure: false,
},
name: "todos-session-id",
resave: false,
saveUninitialized: true,
// figure out what to do with this
secret: "hella insecure",
store: new LokiStore({}),
}));
app.use((req, res, next) => {
let todos = [];
if ("todos" in req.session) {
req.session.todos.forEach(rawTodo => {
todos.push(new Todo(rawTodo))
});
}
req.session.todos = todos;
next();
});
app.use("/api", apiRouter);
let server = app.listen(app.get('port'), () => console.log('listening on port ' + server.address().port));