From 13b64cd1bb57bd719de8fea147add912082612cb Mon Sep 17 00:00:00 2001 From: Thomas Ghysels Date: Sun, 3 Mar 2019 10:40:49 +0100 Subject: [PATCH] Fix redirect with basepath Fix #589 --- runtime/src/server/middleware/get_page_handler.ts | 2 +- test/apps/with-basepath/test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/src/server/middleware/get_page_handler.ts b/runtime/src/server/middleware/get_page_handler.ts index c0a39cc0c..e22f2da96 100644 --- a/runtime/src/server/middleware/get_page_handler.ts +++ b/runtime/src/server/middleware/get_page_handler.ts @@ -177,7 +177,7 @@ export function get_page_handler( try { if (redirect) { - const location = URL.resolve(req.baseUrl || '/', redirect.location); + const location = URL.resolve((req.baseUrl || '') + '/', redirect.location); res.statusCode = redirect.statusCode; res.setHeader('Location', location); diff --git a/test/apps/with-basepath/test.ts b/test/apps/with-basepath/test.ts index bfb50d8a9..a81875dfd 100644 --- a/test/apps/with-basepath/test.ts +++ b/test/apps/with-basepath/test.ts @@ -13,6 +13,7 @@ describe('with-basepath', function() { let page: puppeteer.Page; let base: string; + // helpers let start: () => Promise; let prefetchRoutes: () => Promise; let title: () => Promise; @@ -63,14 +64,13 @@ describe('with-basepath', function() { 'custom-basepath/global.css', 'custom-basepath/index.html', 'custom-basepath/redirect-from/index.html', - 'custom-basepath/redirect-to', + 'custom-basepath/redirect-to/index.html', 'custom-basepath/service-worker-index.html', 'custom-basepath/service-worker.js' ]); }); it('redirects on server', async () => { - console.log('base', base) await page.goto(`${base}/custom-basepath/redirect-from`); assert.equal(