forked from faisalman/ua-parser-js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
47 lines (43 loc) · 1.18 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
const http = require("http");
const fs = require("fs").promises;
const host = "localhost";
const port = 8080;
const server = http.createServer((req, res) => {
switch (req.url) {
case "/page-using-rkey":
fs.readFile(__dirname + "/src/__pages__/page-using-rkey.html").then(
(contents) => {
res.setHeader("Content-Type", "text/html");
res.writeHead(200);
res.end(contents);
},
);
break;
case "/page-using-rkey-headers":
fs.readFile(
__dirname + "/src/__pages__/page-using-rkey-headers.html",
).then((contents) => {
res.setHeader("Content-Type", "text/html");
res.writeHead(200);
res.end(contents);
});
break;
case "/stop-server":
res.end();
server.close();
process.exit(1);
break;
case "/parser.js":
fs.readFile(__dirname + "/lib/ua-parser.min.js").then(
(contents) => {
res.setHeader("Content-Type", "text/javascript");
res.writeHead(200);
res.end(contents);
},
);
break;
}
});
server.listen(port, host, () => {
console.log(`Server is running on http://${host}:${port}`);
});