-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
71 lines (57 loc) · 1.63 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
const express = require("express");
const app = express();
const blocklisted = [];
app.get("*", function (req, res, next) {
var matched = blocklisted.some(re => re.test(req.originalUrl.replace(/\?.*$/, '')))
if (matched) {
var ip = req.headers['x-forwarded-for'] || req.socket.remoteAddress;
res.status(403);
res.type('txt').send('Forbidden');
} else {
next();
}
})
app.use("/public", express.static(__dirname + "/public"))
app.get("/", function (req, res) {
var ip = req.headers['x-forwarded-for'] || req.socket.remoteAddress;
res.sendFile(__dirname + "/index.html")
console.log("Served index to " + ip)
})
app.get("/fsedit", function (req, res) {
var ip = req.headers['x-forwarded-for'] || req.socket.remoteAddress;
res.sendFile(__dirname + "/fsedit/index.html")
console.log("Served fsedit to " + ip)
})
app.use(function (req, res, next) {
res.status(404);
// respond with html page
if (req.accepts('html')) {
res.sendFile(__dirname + "/404.html")
return;
}
// respond with json
if (req.accepts('json')) {
res.json({ error: 'Not found' });
return;
}
// default to plain-text. send()
res.type('txt').send('Not found');
});
app.use((err, req, res, next) => {
console.error(err);
res.status(500);
// respond with html page
if (req.accepts('html')) {
res.sendFile(__dirname + "/500.html")
return;
}
// respond with json
if (req.accepts('json')) {
res.json({ error: 'Internal server error' });
return;
}
// default to plain-text. send()
res.type('txt').send('Internal server error');
})
app.listen(3005, "127.0.0.1");
console.log("Live @ 3005");