Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yepolotn1ak committed Jul 8, 2024
1 parent 93b35d8 commit 7491885
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 37 deletions.
32 changes: 21 additions & 11 deletions src/createServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
26 changes: 0 additions & 26 deletions src/index.html

This file was deleted.

0 comments on commit 7491885

Please sign in to comment.