-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathserver.js
More file actions
47 lines (40 loc) · 1.04 KB
/
Copy pathserver.js
File metadata and controls
47 lines (40 loc) · 1.04 KB
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
let http = require("http");
let url = require("url");
let querystring = require("querystring");
let static = require("node-static");
let file = new static.Server(".");
function accept(req, res) {
if (req.url == "/load") {
res.writeHead(200, {
"Content-Type": "text/plain",
"Cache-Control": "no-cache",
"Content-Length": 90000,
});
let i = 0;
let timer = setInterval(write, 1000);
write();
function write() {
res.write(String(i).repeat(10000));
i++;
if (i == 9) {
clearInterval(timer);
res.end();
}
}
} else if (req.url == "/json") {
res.writeHead(200, {
// 'Content-Type': 'application/json;charset=utf-8',
"Cache-Control": "no-cache",
});
res.write(JSON.stringify({ message: "Hello, world!" }));
res.end();
} else {
file.serve(req, res);
}
}
// ----- Konsoldan server sifatida yoki modul sifatida accept ni ishga tushiring ------
if (!module.parent) {
http.createServer(accept).listen(8080);
} else {
exports.accept = accept;
}