-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
56 lines (46 loc) · 1.3 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
45
46
47
48
49
50
51
52
53
54
55
56
/*
* app.js
* Copyright (c) 2019, Texx
* License: MIT
* See https://github.com/texxme/Texx/blob/master/LICENSE
*/
import { ExpressPeerServer } from 'peer';
import express, { Router } from 'express';
import path from 'path';
import logger from 'morgan';
import bodyParser from 'body-parser';
const app = express();
app.disable('x-powered-by');
const routes = Router();
const server = app.listen(8080, '0.0.0.0');
const peerServer = ExpressPeerServer(server, { debug: true });
peerServer.on('connection', id => console.log(`New connection: ${id}`));
routes.get('/', (req, res) => {
res.render('index');
});
app.use('/api', peerServer);
// View engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use(logger('dev', {
skip: () => app.get('env') === 'test',
}));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'dist')));
// Routes
app.use('/', routes);
// Catch 404 and forward to error handler
app.use((req, res, next) => {
const err = new Error('Not Found');
err.status = 404;
next(err);
});
// Error handler
app.use((err, req, res, next) => { // eslint-disable-line no-unused-vars
res
.status(err.status || 500)
.render('error', {
message: err.message,
});
});