diff --git a/src/createServer.js b/src/createServer.js index 1fc5f4e..54a844b 100644 --- a/src/createServer.js +++ b/src/createServer.js @@ -1,9 +1,22 @@ /* eslint-disable no-console */ 'use strict'; +const http = require('http'); + function createServer() { - /* Write your code here */ - // Return instance of http.Server class + return http.createServer((req, res) => { + const normalizedUrl = new URL(req.url, `http://${req.headers.host}`); + const parts = normalizedUrl.pathname + .slice(1) + .split('/') + .filter((part) => part.length > 0); + const query = Object.fromEntries(normalizedUrl.searchParams.entries()); + + console.log('Received request:', { parts, query }); + + res.writeHead(200, { 'Content-Type': 'application/json' }); + res.end(JSON.stringify({ parts, query })); + }); } module.exports = {