-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
34 lines (25 loc) · 1.21 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
require('dotenv').config();
const http = require('http');
const config = require('config');
const express = require('express');
const level = require('level');
const sublevel = require('level-sublevel');
const usersFactory = require('./lib/users');
const messageFactory = require('./lib/message');
const webRouterFactory = require('./routers/web');
const apiRouterFactory = require('./routers/api');
const db = sublevel(level('./data/db'));
const users = usersFactory(db.sublevel('users'));
// message represents a shared resource that users must be authenticated/authorized to access
const message = messageFactory(db.sublevel('message'), users);
const webRouter = webRouterFactory(db, users, message);
const apiRouter = apiRouterFactory(users, message);
const app = express();
app.set('trust proxy', config.has('session.secure') ? config.get('session.secure') : false);
app.set('view engine', 'pug');
app.use('/api', apiRouter);
app.use('/', webRouter);
const server = http.createServer(app);
const port = config.has('server.internalPort') ? config.get('server.internalPort') : config.get('server.port');
// eslint-disable-next-line no-console
server.listen(port, () => { console.log(`server listening on port ${port}`); });