-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
server.js
48 lines (45 loc) · 1.54 KB
/
server.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
import express from 'express';
import session from 'express-session';
import memorystore from 'memorystore';
import ejs from 'ejs';
import Docker from 'dockerode';
import { router } from './router/index.js';
import { sequelize } from './database/models.js';
export const docker = new Docker();
// Session middleware
const MemoryStore = memorystore(session);
const sessionMiddleware = session({
store: new MemoryStore({ checkPeriod: 86400000 }), // Prune expired entries every 24h
secret: "keyboard cat",
resave: false,
saveUninitialized: false,
cookie:{
secure: false,
httpOnly: false,
maxAge: 3600000 * 8 // Session max age in milliseconds. 3600000 = 1 hour.
}
});
// Express middleware
const app = express();
const PORT = process.env.PORT || 8000;
app.set('view engine', 'html');
app.engine('html', ejs.renderFile);
app.use([
express.static('public'),
express.urlencoded({ extended: true }),
sessionMiddleware,
router
]);
// Initialize server
app.listen(PORT, async () => {
async function init() {// I made sure the console.logs and emojis lined up
try { await sequelize.authenticate().then(
() => { console.log('DB Connection: ✔️') }); }
catch { console.log('DB Connection: ❌'); }
try { await sequelize.sync().then(
() => { console.log('Synced Models: ✔️') }); }
catch { console.log('Synced Models: ❌'); } }
await init().then(() => {
console.log(`Listening on http://localhost:${PORT}`);
});
});