-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
70 lines (53 loc) · 1.85 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
process.chdir(__dirname)
const express = require('express');
const app = express();
const server = require('http').createServer(app);
const session = require('express-session');
const memory_store = require('memorystore')(session);
const sa_app = require("./private/js/app.js");
const { read_configuration } = require('./private/js/tools.js');
if (sa_app.init('./conf.json') == false)
return 1;
/* ************************************************************************* */
/* App */
// Middlewares
app.use(express.json()); // JSON body parsing
let config = sa_app.get_config()
let session_conf = {
name: "session",
secret: sa_app.auth.generate_token(100),
saveUninitialized: false, // true -> deprecated
resave: false, // true -> deprecated
cookie: {
maxAge: config.cookies.max_days * 24 * 3600 * 1000, // Cookie validity in milliseconds
httpOnly: true
},
store: new memory_store({
checkPeriod: 1 * 24 * 3600 * 1000 // prune expired entries every 24h
}),
};
if (!config.debug)
{
// TODO : make secure cookies work
// session_conf.proxy = true;
// session_conf.cookie.secure = true; // https
session_conf.cookie.domain = config.cookies.domain
}
// With this middleware enabled everything stored in req.session
// is saved *server-side* across requests
app.use(session(session_conf));
// Rendering engine
app.set("view engine", "pug");
// Serve static files
app.use(express.static('public'));
/* ************************************************************************* */
/* Routes */
var root = require('./routes/root')(sa_app);
app.use("/", root);
/* ************************************************************************* */
/* Start */
const port = config.port;
console.log("Starting app on port: " + port);
server.listen(port, () => {
console.log(`App listening on port: ${port}`);
});