Skip to content

Commit fb8226b

Browse files
committed
fix: preserve query string when redirecting
1 parent 1ad564e commit fb8226b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/server.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ interface ManifestLookupOptions {
3434

3535
const FingerprintedExtensions = new Set(['.css', '.js', '.svg']);
3636

37+
function preserveQueryString(req: express.Request, destination: string) {
38+
return req.originalUrl.includes('?')
39+
? `${destination}?${req.originalUrl.split('?')[1]}`
40+
: destination;
41+
}
42+
3743
export const getManifest = async (siteId: string, branchOrRef: string) => {
3844
const keys = [
3945
datastore.key(['Fileset2Manifest', `${siteId}:branch:${branchOrRef}`]),
@@ -304,9 +310,7 @@ export function createApp(siteId: string) {
304310
const result = route.getRedirect(params);
305311
const code = result[0];
306312
let destination = result[1];
307-
destination = req.originalUrl.includes('?')
308-
? `${destination}?${req.originalUrl.split('?')[1]}`
309-
: destination;
313+
destination = preserveQueryString(req, destination);
310314
res.redirect(code, destination);
311315
return;
312316
}
@@ -363,7 +367,7 @@ export function createApp(siteId: string) {
363367
(manifestPaths[`${urlPath}/index.html`] ||
364368
manifestPaths[`${urlPath.toLowerCase()}/index.html`])
365369
) {
366-
const destination = `${urlPath}/`;
370+
const destination = preserveQueryString(req, urlPath);
367371
res.redirect(301, destination);
368372
return;
369373
}

0 commit comments

Comments
 (0)