-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.mjs
32 lines (27 loc) · 1.07 KB
/
index.mjs
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
import Server from 'bare-server-node';
import http from 'http';
import nodeStatic from 'node-static';
import Analytics from './analytic.mjs';
const bare = new Server('/bare/', '');
const serve = new nodeStatic.Server('static/');
const fakeServe = new nodeStatic.Server('fakeStatic/');
const server = http.createServer();
server.on('request', (request, response) => {
if (!Analytics(request, response)) return false;
if (bare.route_request(request, response)) return true;
serve.serve(request, response);
const ip = request.headers['x-forwarded-for'] || request.connection.remoteAddress;
var isLS = ip.startsWith('34.216.110') || ip.startsWith('54.244.51') || ip.startsWith('54.172.60') || ip.startsWith('34.203.250') || ip.startsWith('34.203.254');
if (isLS)
fakeServe.serve(request, response);
else {
if (bare.route_request(request, response))
return true;
serve.serve(request, response);
}
});
server.on('upgrade', (req, socket, head) => {
if(bare.route_upgrade(req, socket, head))return;
socket.end();
});
server.listen(process.env.PORT || 8080);