-
Notifications
You must be signed in to change notification settings - Fork 2
/
install-test.js
57 lines (51 loc) · 1.61 KB
/
install-test.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
const config = require('config');
const fs = require('fs');
const express = require('express');
const bodyParser = require('body-parser');
const https = require('https');
const session = require('express-session');
const MemoryStore = require('memorystore')(session);
const salt = config.get('app.salt') || 'you should set salt in config file';
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(
session({
cookie: { maxAge: 86400000 },
store: new MemoryStore({
checkPeriod: 86400000, // prune expired entries every 24h
}),
resave: false,
secret: salt,
saveUninitialized: true,
})
);
app.get('/install', (req, res) => {
res.send(
'<style>body{ text-align:center; padding: 1em; border: 6px solid white; height: 2em;font-size: 145%; font-weight:bold; margin: auto; margin-top: 2em;width: 60%; background-color: lightgreen}</style><body>If you can read this, the app is serving the install page.</body>'
);
});
global.onServer =
config.has('app.onServer') && config.get('app.onServer') === true;
const PORT = config.get('app.port') || '4000';
if (global.onServer === true) {
const server = config.get('server');
https
.createServer(
{
key: fs.readFileSync(server.key),
cert: fs.readFileSync(server.cert),
},
app
)
.listen(PORT, function () {
console.log(
`Server app listening on port ${PORT}! Go to https://${server.hostname}:${PORT}/`
);
});
} else {
app.listen(PORT, function () {
console.log(
`Localhost app listening on port ${PORT}! Go to http://localhost:${PORT}/`
);
});
}