diff --git a/src/createServer.js b/src/createServer.js index bb32cf5..72cab5a 100644 --- a/src/createServer.js +++ b/src/createServer.js @@ -11,26 +11,36 @@ function createServer() { const server = new http.Server(); server.on('request', (req, res) => { - const url = new URL(req.url, `http://${req.headers.host}`); + const { pathname } = new URL(req.url, `http://${req.headers.host}`); const form = new formidable.IncomingForm(); - if (url.pathname !== '/compress') { - res.statusCode = 404; - res.end('Trying to access a non-existing route!'); + if (pathname === '/' && req.method === 'GET') { + fs.readFile('./public/index.html', (err, data) => { + if (err) { + res.statusCode = 404; + res.end('Not found'); + + return; + } + + res.statusCode = 200; + res.setHeader('Content-type', 'text/html'); + res.end(data); + }); return; } - if (url.req.method !== 'POST') { - res.statusCode = 400; - res.end('Use POST request method instead!'); + if (pathname !== '/compress') { + res.statusCode = 404; + res.end('Trying to access a non-existing route!'); return; } - if (url.pathname === '/' && req.method === 'GET') { - res.statusCode = 200; - res.end('Ready!'); + if (req.method !== 'POST') { + res.statusCode = 400; + res.end('Use POST request method instead!'); return; } @@ -47,7 +57,7 @@ function createServer() { const [file] = files; if (!compressionTypes.includes(compressionType)) { - res.statusCode = 404; + res.statusCode = 400; res.end('Bad Request: Compression type not supported'); return; diff --git a/src/index.html b/src/index.html deleted file mode 100644 index 167e162..0000000 --- a/src/index.html +++ /dev/null @@ -1,26 +0,0 @@ - - - -
- - -