-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (43 loc) · 1.26 KB
/
index.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
const express = require('express');
// set up express app
const app = express();
const fs = require('fs');
const http = require('http');
const https = require('https');
// get local ip
var os = require('os');
var interfaces = os.networkInterfaces();
var addresses = [];
for (var k in interfaces) {
for (var k2 in interfaces[k]) {
var address = interfaces[k][k2];
if (address.family === 'IPv4' && !address.internal) {
addresses.push(address.address);
}
}
}
//app.use(function(req, res, next) {
// if ((req.get('X-Forwarded-Proto') !== 'https')) {
// res.redirect('https://' + req.get('Host') + req.url);
// } else
// next();
// });
// use body-parser middleware
app.use(express.json({ limit: '100MB'}));
// route handler
app.use('/api', require('./routes/api'));
// redirect `/` to `/api/test`
app.get('/', (req, res) => {
res.redirect('/api/test');
});
// error handling
app.use(function(err, req, res, next){
console.log(err);
res.status(422).send({error: err.message});
});
// Start server
app.listen(process.env.port || 80, function(){
console.log('HTTP server running on port 80\n');
});
console.log("\nLocal IP:")
console.log(addresses);