-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
46 lines (37 loc) · 1.1 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
'use strict';
let express = require('express');
let http = require('http');
let path = require('path');
let bodyParser = require('body-parser');
let log = require('./libs/log')(module);
let ChatServer = require('./libs/chat').listen;
let config = require('./config/config.json');
const PORT = config.port;
// Express
const app = express();
const server = app.listen(PORT, () => {
log.info('listening on *:' + PORT);
});
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, 'build')));
// Routes
app.use('/*', (req, res) => {
res.sendFile(path.join(__dirname, '/build/index.html'));
});
// Register Chat
ChatServer(server);
app.use((req, res, next) => {
log.debug('Not found URL: %s', req.url);
res.send(404, { error: 'Not found' });
return;
});
app.use((err, req, res, next) => {
res.status(err.status || 500);
log.error('Internal error(%d): %s', res.statusCode, err.message);
res.send({ error: err.message });
return;
});
app.get('/ErrorExample', (req, res, next) => {
next(new Error('Random error!'));
});