diff --git a/src/createServer.js b/src/createServer.js index 1fc5f4e..d59c774 100644 --- a/src/createServer.js +++ b/src/createServer.js @@ -1,8 +1,23 @@ /* eslint-disable no-console */ 'use strict'; +const http = require('http'); + function createServer() { - /* Write your code here */ + const server = http.createServer((req, res) => { + const url = new URL(req.url, `http://${req.headers.host}`); + + const parts = url.pathname.split('/').filter(Boolean); + + const query = Object.fromEntries(url.searchParams.entries()); + + const result = { parts, query }; + + res.writeHead(200, { 'Content-Type': 'application/json' }); + res.end(JSON.stringify(result)); + }); + + return server; // Return instance of http.Server class }