-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
60 lines (50 loc) · 1.49 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
57
58
59
60
const APP_PATH = 'app'
const PUBLIC_PATH = 'public'
const ejs = require('ejs')
const express = require('express')
const cookieParser = require('cookie-parser')
const bodyParser = require('body-parser')
const http = require('http')
const path = require('path')
const partials = require('express-partials')
const app = express()
const port = process.env.PORT || '3000'
const routes = require('./routes')
// ------- VIEWS
app.use(partials());
app.set('views', path.join(__dirname, APP_PATH + '/views'))
app.set('view engine', 'ejs')
// ------- ROUTES & COOKIES
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended: false}))
app.use(cookieParser('6e5faf306dfd27e6c7599aa4d5039fe7'));
// ------- ROUTES
app.use('/public', express.static(path.join(__dirname, PUBLIC_PATH)));
app.use('/', routes)
// ------- SERVER CONFIG
app.set('port', port)
const server = http.createServer(app)
const io = require('socket.io')(server);
require('./sockets/server')(io);
server.listen(port, function() {})
server.on('error', function(error) {
if (error.syscall !== 'listen') {
throw error;
}
var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
})