-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.js
40 lines (35 loc) · 1.07 KB
/
router.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
import { runCpuIntensiveTask, runSmartCpuIntensiveTask } from './cpu-intensive-tasks.js';
import { runAsyncTask, runSmartAsyncTask } from './async-tasks.js';
import { runMemoryLeakTask, runSmartMemoryLeakTask } from './memory-leak-tasks.js';
function baseRouteHandler(req, res) {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello, World!\n');
}
function cpuRouteHandler(req, res) {
runSmartCpuIntensiveTask(() => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello, World!\n');
})
}
function asyncRouteHandler(req, res) {
runSmartAsyncTask(() => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello, World!\n');
});
}
function memoryLeakRouteHandler(req, res) {
runSmartMemoryLeakTask(() => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello, World!\n');
});
}
export const router = {
'/': baseRouteHandler,
'/cpu': cpuRouteHandler,
'/async': asyncRouteHandler,
'/memory-leak': memoryLeakRouteHandler,
};