-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
36 lines (32 loc) · 972 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
29
30
31
32
33
34
35
36
// Set these to whichever unoccupied port you'd like to use
const httpServerPort = 8080;
const corsProxyPort = 8081;
let corsProxy = require('cors-anywhere');
let httpServer = require("http-server");
function logger(req, res, error) {
var date = new Date();
var ip = '';
if (error) {
console.log(
'[%s] %s "%s %s" Error (%s): "%s"',
date, ip, req.method, req.url,
error.status.toString(), error.message
);
}
else {
console.log(
'[%s] %s "%s %s" "%s"',
date, ip, req.method, req.url,
req.headers['user-agent']
);
}
}
let options = {
"proxy": "http://localhost:" + corsProxyPort,
"cache": -1,
"logFn": logger
};
corsProxy.createServer().listen(corsProxyPort);
httpServer.createServer(options).listen(httpServerPort, () => {
console.log(`Server started. Visit http://localhost:${httpServerPort}/ to access web interface.`);
});