-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
28 lines (23 loc) · 866 Bytes
/
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
const express = require('express')
const resolve_location = require('./resolve_location');
const fs = require('fs');
const redirectPathMap = JSON.parse(fs.readFileSync('pathMap.json'));
const app = express();
const port = 8080;
app.get(/.*/, (req, res) => {
const ip = req.connection.remoteAddress;
const path = req.originalUrl;
// var ip = '192.168.20.10';
console.log(`Ip: ${ip}, path ${path}`);
resolve_location.resolve_location(ip)
.then(response => {
var host = redirectPathMap[response],
host = host === null || typeof host === 'undefined' ? redirectPathMap['EU'] : host;
console.log(`Ip: ${ip}, path: ${path}, host:${host}`);
res.redirect(host+path);
})
.catch(error => {
res.send(error);
})
})
app.listen(port, () => console.log(`App listening on port ${port}!`));