forked from hrntknr/ldap-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
44 lines (33 loc) · 1.07 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
#!/usr/bin/env node
const http = require('http');
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const {log} = require('./lib');
const index = require('./routes')(log.logger);
const api = require('./routes/api')(log.logger);
const port = process.env.port || 3000;
const app = express();
const server = http.createServer(app);
app.set('port', port);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use(log.connectLogger);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(express.static(path.join(__dirname, 'public')));
app.use('/api/', api);
app.use('/', index);
server.on('listening', () => {
const addr = server.address();
const address = addr.family === 'IPv6' ? `[${addr.address}]` : addr.address;
log.logger.info(`Listening on ${address}:${addr.port}`);
});
server.on('error', (err) => {
log.logger.error(err.stack);
throw err;
});
process.on('unhandledRejection', (err) => {
log.logger.error(err.stack);
});
server.listen(port);