Skip to content

Commit

Permalink
updated url parsing syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
AustinWilloughby committed Aug 20, 2024
1 parent 3509068 commit ab2eb04
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/jsonResponses.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const success = (request, response) => {
return respondJSON(request, response, 200, responseJSON);
};

const badRequest = (request, response, params) => {
const badRequest = (request, response) => {

Check failure on line 15 in src/jsonResponses.js

View workflow job for this annotation

GitHub Actions / build (20.x)

'request' is defined but never used

Check failure on line 15 in src/jsonResponses.js

View workflow job for this annotation

GitHub Actions / build (20.x)

'response' is defined but never used
const responseJSON = {

Check failure on line 16 in src/jsonResponses.js

View workflow job for this annotation

GitHub Actions / build (20.x)

'responseJSON' is assigned a value but never used
message: 'This request has the required parameters',
};
Expand Down
9 changes: 4 additions & 5 deletions src/server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const http = require('http');
const url = require('url');
const query = require('querystring');

Check failure on line 2 in src/server.js

View workflow job for this annotation

GitHub Actions / build (20.x)

'query' is assigned a value but never used
const htmlHandler = require('./htmlResponses.js');
const jsonHandler = require('./jsonResponses.js');
Expand All @@ -14,14 +13,14 @@ const urlStruct = {
};

const onRequest = (request, response) => {
const parsedUrl = url.parse(request.url);

const protocol = request.connection.encrypted ? 'https' : 'http';
const parsedUrl = new URL(request.url, `${protocol}://${request.headers.host}`);

const handlerFunc = urlStruct[parsedUrl.pathname];
if (handlerFunc) {
handlerFunc(request, response, params);
handlerFunc(request, response);
} else {
urlStruct.notFound(request, response, params);
urlStruct.notFound(request, response);
}

};
Expand Down

0 comments on commit ab2eb04

Please sign in to comment.