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 = {