|
1 | | -import worker_threads from "node:worker_threads"; |
2 | | -import { cpus } from "node:os"; |
3 | | -import url from "node:url"; |
4 | | -import path from "node:path"; |
5 | | -import uws from "uWebSockets.js"; |
| 1 | +import worker_threads from 'node:worker_threads' // eslint-disable-line |
| 2 | +import { cpus } from 'node:os' |
| 3 | +import url from 'node:url' |
| 4 | +// import path from 'node:path' |
| 5 | +import uws from 'uWebSockets.js' |
6 | 6 |
|
7 | | -var __filename = url.fileURLToPath(import.meta.url); |
8 | | -var __dirname = path.dirname(__filename); |
| 7 | +const __filename = url.fileURLToPath(import.meta.url) |
| 8 | +// const __dirname = path.dirname(__filename) |
9 | 9 |
|
| 10 | +// eslint-disable-next-line |
10 | 11 | if (worker_threads.isMainThread) { |
11 | 12 | for (let i = cpus().length - 1; i >= 0; --i) { |
12 | | - new worker_threads.Worker(__filename); |
| 13 | + // eslint-disable-next-line |
| 14 | + new worker_threads.Worker(__filename) |
13 | 15 | } |
14 | 16 | } else { |
15 | | - const app = uws.App(); |
| 17 | + const app = uws.App() |
16 | 18 |
|
17 | 19 | app |
18 | | - .ws("/*", { |
| 20 | + .ws('/*', { |
19 | 21 | compression: uws.DISABLED, |
20 | 22 | maxPayloadLength: 512 * 1024 * 1024, |
21 | 23 | maxBackpressure: 128 * 1024, |
22 | 24 | idleTimeout: 60, |
23 | 25 | message: (ws, message, isBinary) => { |
24 | 26 | /* Here we echo the message back, using compression if available */ |
25 | | - const ok = ws.send(message, isBinary); |
26 | | - }, |
| 27 | + const ok = ws.send(message, isBinary) // eslint-disable-line |
| 28 | + } |
27 | 29 | }) |
28 | | - .get("/*", (res, req) => { |
| 30 | + .get('/*', (res, req) => { |
29 | 31 | /* It does Http as well */ |
30 | 32 | res |
31 | | - .writeStatus("200 OK") |
32 | | - .end("Hello there!"); |
| 33 | + .writeStatus('200 OK') |
| 34 | + .end('Hello there!') |
33 | 35 | }) |
34 | 36 | .listen(5001, (listenSocket) => { |
35 | 37 | if (listenSocket) { |
| 38 | + // eslint-disable-next-line |
36 | 39 | if (worker_threads.threadId === 0) { |
37 | | - console.log("Listening to port 5001"); |
| 40 | + console.log('Listening to port 5001') |
38 | 41 | } else { |
| 42 | + // eslint-disable-next-line |
39 | 43 | console.log(`Listening to port 5001 from thread ${worker_threads.threadId}`) |
40 | 44 | } |
41 | 45 | } |
42 | | - }); |
| 46 | + }) |
43 | 47 | } |
0 commit comments