From 9cbcbea74e49194373d1d3f1e0cd54d1eb146d25 Mon Sep 17 00:00:00 2001 From: Vladislav-Korsun Date: Mon, 30 Mar 2026 13:36:30 +0300 Subject: [PATCH] add task solution --- src/createServer.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/createServer.js b/src/createServer.js index 1fc5f4e..1c5f1d0 100644 --- a/src/createServer.js +++ b/src/createServer.js @@ -1,9 +1,29 @@ /* eslint-disable no-console */ 'use strict'; +const http = require('http'); + function createServer() { - /* Write your code here */ - // Return instance of http.Server class + const server = http.createServer((req, res) => { + const url = new URL(req.url || '', `http://${req.headers.host}`); + + const pathname = url.pathname; + + const parts = pathname.split('/').filter(Boolean); + + const query = Object.fromEntries(url.searchParams); + + res.setHeader('Content-Type', 'application/json'); + + res.end( + JSON.stringify({ + parts, + query, + }), + ); + }); + + return server; } module.exports = {