-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
73 lines (62 loc) · 1.84 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
64
65
66
67
68
69
70
71
72
73
const express = require('express'),
bodyParser = require('body-parser'),
path = require('path'),
app = express(),
http = require('http').Server(app),
localtunnel = require('localtunnel'),
io = require('socket.io')(http),
mongoose = require('mongoose');
mongoose.connect('mongodb://127.0.0.1/Maxi77', (err) => {
if (err) console.log(err);
else console.log('Connected to database');
});
let testMode = process.argv.slice(2)[0] === 'test';
// testMode = true; //REMOVE THIS
if (testMode) {
console.log('Running app in testmode');
} else {
console.log('Running app in pi mode');
}
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.json());
app.use('/api/weather', require('./controllers/api/weatherController'));
const port = 8001;
http.listen(port);
console.log('Server running at port 8000');
require('./models/journey');
require('./services/bootstrapper.js')(testMode);
require('./socket/socketIncoming.js')(io);
require('./socket/socketOutgoing.js')(io);
var tunnel;
var startTunnel = () => {
tunnel = localtunnel(port, {
subdomain: 'maxi77'
}, function (err, tunnel) {
if (err) {
console.log('There was an error starting localtunnel: ' + err);
}
console.log('Localtunnel running at: ' + tunnel.url);
tunnel.url;
});
};
startTunnel();
tunnel.on('close', function () {
console.log('close');
// setTimeout(startTunnel, 10000);
process.exit(1);
});
tunnel.on('error', function (err) {
console.log(err);
// setTimeout(startTunnel, 10000);
process.exit(1);
});
process.on('uncaughtException', function (er) {
console.log(er);
// setTimeout(startTunnel, 10000);
process.exit(1);
});
tunnel.on('close', function () {
console.log('close');
// setTimeout(startTunnel, 10000);
process.exit(1);
});