-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtzserver.js
43 lines (33 loc) · 986 Bytes
/
tzserver.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
#!/usr/bin/env node
const http = require("http");
const tzInfo = require("./tzinfo");
const host = '0.0.0.0';
const port = 10000;
const requestListener = function (req, res)
{
var url = new URL("http://path.abc" + req.url);
tzName = url.searchParams.get("tzname");
if (tzName == undefined)
{
tzName = "etc/utc";
}
var entry = tzInfo.tzInfo.find(entry =>
entry.name.localeCompare(tzName, undefined,
{ sensitivity: 'accent' }) === 0);
if (entry === undefined)
{
entry = tzInfo.tzInfo.find(entry => entry.name === "etc/utc");
}
console.log("Request: " + tzName);
console.log("Result:");
console.log(entry);
console.log("");
res.setHeader("Content-Type", "application/json");
res.writeHead(200);
res.end(JSON.stringify(entry));
};
const server = http.createServer(requestListener);
server.listen(port, host, () =>
{
console.log(`Server is running on http://${host}:${port}`);
});