summaryrefslogtreecommitdiff
path: root/packages/integrations/node/src
diff options
context:
space:
mode:
authorGravatar Riki <riki_1020@163.com> 2023-06-06 23:09:00 +0800
committerGravatar GitHub <noreply@github.com> 2023-06-06 10:09:00 -0500
commit409c60028aaab09b8f2383ef5730531cd23db4ba (patch)
tree68bc3be1341d7a82f90edb51bb219387115556eb /packages/integrations/node/src
parent144813f7308dcb9de64ebe3f0f2c6cba9ad81eb1 (diff)
downloadastro-409c60028aaab09b8f2383ef5730531cd23db4ba.tar.gz
astro-409c60028aaab09b8f2383ef5730531cd23db4ba.tar.zst
astro-409c60028aaab09b8f2383ef5730531cd23db4ba.zip
fix:query not considered in directory redirection (#7243)
* fix:query not considered in directory redirection * feat: req.url may be empty * test(node): add redirect + query param tests * refactor(node): cleanup query param logic * chore: remove log * chore: add changeset --------- Co-authored-by: Riki <947968273@qq.com> Co-authored-by: Nate Moore <nate@astro.build> Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
Diffstat (limited to 'packages/integrations/node/src')
-rw-r--r--packages/integrations/node/src/http-server.ts9
1 files changed, 8 insertions, 1 deletions
diff --git a/packages/integrations/node/src/http-server.ts b/packages/integrations/node/src/http-server.ts
index 177c71ed9..9f8b3e891 100644
--- a/packages/integrations/node/src/http-server.ts
+++ b/packages/integrations/node/src/http-server.ts
@@ -57,7 +57,14 @@ export function createServer(
});
stream.on('directory', () => {
// On directory find, redirect to the trailing slash
- const location = req.url + '/';
+ let location: string;
+ if (req.url!.includes('?')) {
+ const [url = '', search] = req.url!.split('?');
+ location = `${url}/?${search}`
+ } else {
+ location = req.url + '/'
+ }
+
res.statusCode = 301;
res.setHeader('Location', location);
res.end(location);