-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
63 lines (46 loc) · 1.7 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// external dependencies
const express = require('express');
const favicon = require('serve-favicon');
const app = express();
const path = require('path');
const bodyParser = require('body-parser');
const db = require('./models/wrapper.js');
const enforce = require('express-sslify');
const http = require('http').Server(app);
// Start the server
if(process.env.NODE_ENV === 'production'){
app.use(enforce.HTTPS({ trustProtoHeader: true }));
}
const port = process.env.PORT || 8080;
const server = http.listen(port, function() {
let host = server.address().address;
// replace IPv6 wildcard by a recognizable URL, that can be used in a browser
// address bar
host = host.replace(/^::$/, '0.0.0.0');
// Printed thus, some terminals display a clickable link
console.log('FORWARDboard is running at http://%s:%s/', host, server.address().port);
});
const io = require('socket.io')(http);
app.set('socketio', io);
/******* CONFIG *******/
// Use body parser for requests
app.use(bodyParser.urlencoded({
extended: true
}));
// Serve all files from static
app.use(favicon(__dirname + '/static/images/favicon11.png'));
app.use('/static', express.static(path.join(__dirname, '/static')));
// Handle api traffic
const api = require('./routes/api')(io, db);
app.use('/api', api);
// Handle s3 file uploading
const awsApi = require('./routes/awsapi')(io, db);
app.use('/aws', awsApi);
// Main board (on computer screens)
const browserRoutes = require('./routes/browser')(api, __dirname);
app.use('/', browserRoutes);
// Handle socket logic
require('./routes/sockets')(io, db);
// Twilio input
const twilio = require('./routes/twilio')(io, db);
app.post('/twilio', twilio.POSTtext);