From b23cf2039a9959d1037e7e776533cd0214c55649 Mon Sep 17 00:00:00 2001 From: tynanbe Date: Fri, 18 Mar 2022 15:04:52 -0500 Subject: [PATCH] Accept query string in request --- src/utils/getFilePath.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/utils/getFilePath.js b/src/utils/getFilePath.js index 42dd22e..1316f63 100644 --- a/src/utils/getFilePath.js +++ b/src/utils/getFilePath.js @@ -3,14 +3,15 @@ import { options } from '../index.js'; export const getFilePath = request => { const { root } = options; + const url = new URL(request.url, `http://${request.headers.host}`); - if (request.url == '/') return `${root}/index.html`; + if (url.pathname == '/') return `${root}/index.html`; - if (!request.url.includes('.')) { - const testFilepath = `${root}/${request.url}.html`; + if (!url.pathname.includes('.')) { + const testFilepath = `${root}/${url.pathname}.html`; if (fs.existsSync(testFilepath)) return testFilepath; } - return root + request.url; + return root + url.pathname; };