diff --git a/src/createServer.js b/src/createServer.js index 1fc5f4e..71ec133 100644 --- a/src/createServer.js +++ b/src/createServer.js @@ -1,9 +1,25 @@ /* 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 [pathPart, queryPart] = req.url.split('?'); + const pathParts = pathPart.split('/').filter((part) => part !== ''); + const params = new URLSearchParams(queryPart); + const resultParams = Object.fromEntries(params); + + const responseBody = { + parts: pathParts, + query: resultParams, + }; + + res.writeHead(200, 'OK', { 'Content-type': 'application/json' }); + res.end(JSON.stringify(responseBody)); + }); + + return server; } module.exports = {