(req: IncomingMessage, res: ServerResponse)
| 70 | } |
| 71 | |
| 72 | #handle(req: IncomingMessage, res: ServerResponse) { |
| 73 | const url = req.url ?? ''; |
| 74 | const routeHandler = this.#routes[url]; |
| 75 | |
| 76 | if (routeHandler) { |
| 77 | routeHandler(req, res); |
| 78 | } else { |
| 79 | res.writeHead(404, {'Content-Type': 'text/html'}); |
| 80 | res.end( |
| 81 | html`<h1>404 - Not Found</h1><p>The requested page does not exist.</p>`, |
| 82 | ); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | restore() { |
| 87 | this.#routes = {}; |