From 9c688acbda4d0b0c94975d9318b2734a479371d2 Mon Sep 17 00:00:00 2001 From: Iryna Knyzh Date: Thu, 12 Feb 2026 10:56:27 +0200 Subject: [PATCH] task --- src/createServer.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/createServer.js b/src/createServer.js index 1fc5f4e..71e8b83 100644 --- a/src/createServer.js +++ b/src/createServer.js @@ -1,9 +1,26 @@ /* eslint-disable no-console */ 'use strict'; +const http = require('node:http'); + function createServer() { - /* Write your code here */ - // Return instance of http.Server class + const server = http.createServer((req, res) => { + const host = req.headers.host || 'localhost'; + const url = new URL(req.url || '/', `http://${host}`); + const parts = url.pathname.split('/').filter(Boolean); + const query = Object.fromEntries(url.searchParams.entries()); + + const body = { + parts, + query, + }; + + res.setHeader('Content-Type', 'application/json'); + res.statusCode = 200; + res.end(JSON.stringify(body)); + }); + + return server; } module.exports = {