8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6848249 commit 5eb1b2dCopy full SHA for 5eb1b2d
JavaScript/helpers/server.js
@@ -1,7 +1,6 @@
1
'use strict';
2
3
const http = require('node:http');
4
-const url = require('node:url');
5
6
const routes = {
7
'/': (request, callback) => {
@@ -27,19 +26,12 @@ const routes = {
27
26
};
28
29
const server = http.createServer((req, res) => {
30
- const parsedUrl = url.parse(req.url);
31
- let path = parsedUrl.pathname;
32
- if (path.endsWith('/') && path.length > 1) {
33
- path = path.slice(0, -1);
34
- }
35
-
36
- const handler = routes[path];
+ const handler = routes[req.url];
37
if (!handler) {
38
res.writeHead(404);
39
res.end('Not found');
40
return;
41
}
42
43
handler(req, (result) => {
44
const json = JSON.stringify(result);
45
res.writeHead(200, { 'Content-Type': 'application/json' });
0 commit comments