From 6ac5b7518e41dd4f82f9739bffd15e4e9dc1413c Mon Sep 17 00:00:00 2001 From: Diogo Martins Date: Fri, 13 Feb 2026 12:22:06 +0000 Subject: [PATCH] Fix node errors --- docs/content/servers/node.md | 9 +++++++-- src/Servers/NodeServer/server.js | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/content/servers/node.md b/docs/content/servers/node.md index dcb9557..4a21d32 100644 --- a/docs/content/servers/node.md +++ b/docs/content/servers/node.md @@ -23,8 +23,13 @@ const http = require('http'); const port = parseInt(process.argv[2] || '8080', 10); const server = http.createServer((req, res) => { - const url = new URL(req.url, `http://${req.headers.host}`); - if (url.pathname === '/echo') { + let pathname; + try { + pathname = new URL(req.url, `http://${req.headers.host || 'localhost'}`).pathname; + } catch { + pathname = req.url; + } + if (pathname === '/echo') { let body = ''; for (const [name, value] of Object.entries(req.headers)) { if (Array.isArray(value)) value.forEach(v => body += name + ': ' + v + '\n'); diff --git a/src/Servers/NodeServer/server.js b/src/Servers/NodeServer/server.js index da31181..1526756 100644 --- a/src/Servers/NodeServer/server.js +++ b/src/Servers/NodeServer/server.js @@ -3,8 +3,13 @@ const http = require('http'); const port = parseInt(process.argv[2] || '8080', 10); const server = http.createServer((req, res) => { - const url = new URL(req.url, `http://${req.headers.host}`); - if (url.pathname === '/echo') { + let pathname; + try { + pathname = new URL(req.url, `http://${req.headers.host || 'localhost'}`).pathname; + } catch { + pathname = req.url; + } + if (pathname === '/echo') { let body = ''; for (const [name, value] of Object.entries(req.headers)) { if (Array.isArray(value)) value.forEach(v => body += name + ': ' + v + '\n');