-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.js
More file actions
30 lines (25 loc) · 696 Bytes
/
worker.js
File metadata and controls
30 lines (25 loc) · 696 Bytes
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
const fs = require("fs")
const { parentPort } = require("worker_threads")
parentPort.on("message", (url) => {
let result = {};
fs.readFile('index.html', function (err, html) {
if (err) {
throw err;
}
console.log(url)
if (url != null && url == "/" || url == "/index.html" ) {
result = {
status: 200,
contentType: "text/html",
content: html
}
} else {
result = {
status: 400,
contentType: "text/plain",
content: "Sorry!!!"
}
}
});
parentPort.postMessage(result)
})