-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathserver.js
More file actions
49 lines (40 loc) · 1.26 KB
/
server.js
File metadata and controls
49 lines (40 loc) · 1.26 KB
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
'use strict';
/* Begin by configuring variables */
const express = require('express');
const app = express();
const http = require('http').Server(app);
const compression = require('compression');
const helmet = require('helmet');
const chalk = require('chalk');
const RoomList = require('./src/RoomList.js');
const winston = require('winston');
const port = process.env.PORT || 3000;
/* Set up express middleware before launch */
app.set('view engine', 'html');
app.engine('html', require('ejs').renderFile);
app.set('views', __dirname + '/views');
app.use(compression());
app.use(helmet({noSniff: false}));
app.use(express.static(__dirname + '/public'));
/* Set up our routes (found in src/router.js) */
app.use('/', require('./src/router'));
/* handle 400 errors */
app.use(function(req, res) {
res.status(400);
res.render('400');
});
/* handle 500 errors */
app.use(function(error, req, res, next) {
res.status(500);
res.render('500');
});
/* Set up our RoomList */
global.Rooms = new RoomList();
/* Set up our sockets (found in src/sockets.js) */
const io = require('socket.io')(http);
require('./src/sockets')(io);
/* Finally, start listening */
http.listen(port, error => {
if (error) winston.error(error);
winston.info("Now listening on port " + chalk.green(port));
});