forked from Hideipnetwork/hideipnetwork-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (48 loc) · 1.58 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
53
54
55
import createBareServer from '@tomphttp/bare-server-node';
import express from 'express';
import http from 'http';
import fs from "fs"
const httpServer = http.createServer();
const app = express()
const port = process.env.PORT || 3000;
const bareServer = createBareServer('/bare/', {});
// #############################################################################
// hideipnetwork service
httpServer.on('request', (req, res) => {
if (bareServer.shouldRoute(req)) {
bareServer.routeRequest(req, res);
} else {
app(req, res);
}
});
httpServer.on('upgrade', (req, socket, head) => {
if (bareServer.shouldRoute(req)) {
bareServer.routeUpgrade(req, socket, head);
} else {
socket.end();
}
});
// #############################################################################
// Logs all request paths and method
app.use(function (req, res, next) {
res.set('x-timestamp', Date.now())
res.set('x-powered-by', 'hideip.network')
console.log(`[${new Date().toISOString()}] ${req.ip} ${req.method} ${req.path}`);
next();
});
// #############################################################################
// This configures static hosting for files in /public that have the extensions
// listed in the array.
const options = {
dotfiles: 'ignore',
etag: false,
extensions: ['htm', 'html', 'css', 'js', 'ico', 'jpg', 'jpeg', 'png', 'svg'],
index: ['index.html'],
maxAge: '1m',
redirect: false
}
app.use('/', express.static('public', options))
httpServer.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
// module.exports = app