Fix redirect with basepath

Fix #589
This commit is contained in:
Thomas Ghysels
2019-03-03 10:40:49 +01:00
parent 9522cb4539
commit 13b64cd1bb
2 changed files with 3 additions and 3 deletions

View File

@@ -177,7 +177,7 @@ export function get_page_handler(
try { try {
if (redirect) { if (redirect) {
const location = URL.resolve(req.baseUrl || '/', redirect.location); const location = URL.resolve((req.baseUrl || '') + '/', redirect.location);
res.statusCode = redirect.statusCode; res.statusCode = redirect.statusCode;
res.setHeader('Location', location); res.setHeader('Location', location);

View File

@@ -13,6 +13,7 @@ describe('with-basepath', function() {
let page: puppeteer.Page; let page: puppeteer.Page;
let base: string; let base: string;
// helpers
let start: () => Promise<void>; let start: () => Promise<void>;
let prefetchRoutes: () => Promise<void>; let prefetchRoutes: () => Promise<void>;
let title: () => Promise<string>; let title: () => Promise<string>;
@@ -63,14 +64,13 @@ describe('with-basepath', function() {
'custom-basepath/global.css', 'custom-basepath/global.css',
'custom-basepath/index.html', 'custom-basepath/index.html',
'custom-basepath/redirect-from/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-index.html',
'custom-basepath/service-worker.js' 'custom-basepath/service-worker.js'
]); ]);
}); });
it('redirects on server', async () => { it('redirects on server', async () => {
console.log('base', base)
await page.goto(`${base}/custom-basepath/redirect-from`); await page.goto(`${base}/custom-basepath/redirect-from`);
assert.equal( assert.equal(