diff --git a/src/createServer.js b/src/createServer.js index 1fc5f4e..df3e670 100644 --- a/src/createServer.js +++ b/src/createServer.js @@ -1,9 +1,24 @@ /* 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 fullUrl = new URL(req.url, 'http://localhost'); + const fullPath = + fullUrl.host === 'localhost' + ? fullUrl.pathname + : `/${fullUrl.host}${fullUrl.pathname}`; + const parts = fullPath.split('/').filter(Boolean); + const query = Object.fromEntries(fullUrl.searchParams); + + res.statusCode = 200; + res.setHeader('Content-Type', 'application/json'); + res.end(JSON.stringify({ parts, query })); + }); + + return server; } module.exports = {