From accd0e65977b4609c5b5409d1a15e29d3a366a39 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Fri, 9 Dec 2022 15:10:59 -0800 Subject: [PATCH 1/4] Set Vite base URL --- packages/kit/src/exports/vite/index.js | 2 +- .../kit/test/apps/options/source/template.html | 2 +- packages/kit/test/apps/options/test/test.js | 16 +++++++++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index 51995ef87bba..e4fabf7871d5 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -253,7 +253,7 @@ function kit({ svelte_config }) { /** @type {import('vite').UserConfig} */ const result = { appType: 'custom', - base: './', + base: svelte_config.kit.paths.base, build: { rollupOptions: { // Vite dependency crawler needs an explicit JS entry point diff --git a/packages/kit/test/apps/options/source/template.html b/packages/kit/test/apps/options/source/template.html index 5b4fa5d89d58..3a12690637fb 100644 --- a/packages/kit/test/apps/options/source/template.html +++ b/packages/kit/test/apps/options/source/template.html @@ -9,6 +9,6 @@

I am in the template

%sveltekit.body%
- outside app target + outside app target diff --git a/packages/kit/test/apps/options/test/test.js b/packages/kit/test/apps/options/test/test.js index 516536c6cfc4..941a7fa91e72 100644 --- a/packages/kit/test/apps/options/test/test.js +++ b/packages/kit/test/apps/options/test/test.js @@ -9,9 +9,15 @@ test.describe('base path', () => { test('serves a useful 404 when visiting unprefixed path', async ({ request }) => { const html = await request.get('/slash/', { headers: { Accept: 'text/html' } }); expect(html.status()).toBe(404); - expect(await html.text()).toBe( - 'Not found (did you mean /path-base/slash/?)' - ); + if (process.env.DEV) { + // Vite's message + expect(await html.text()).toBe( + 'The server is configured with a public base URL of /path-base - did you mean to visit /path-base/slash/ instead?' + ); + } else { + // SvelteKit's message + expect(await html.text()).toBe('Not found (did you mean /path-base/slash/?)'); + } const plain = await request.get('/slash/'); expect(plain.status()).toBe(404); @@ -248,9 +254,9 @@ test.describe('Vite options', () => { test.describe('Routing', () => { test('ignores clicks outside the app target', async ({ page }) => { - await page.goto('/path-base/routing/link-outside-app-target/source'); + await page.goto('/path-base/routing/link-outside-app-target/source/'); - await page.click('[href="/path-base/routing/link-outside-app-target/target"]'); + await page.click('[href="/path-base/routing/link-outside-app-target/target/"]'); await expect(page.locator('h2')).toHaveText('target: 0'); }); }); From 73b9c17f3e01444b9868649ecf8736a04c75e1dc Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Fri, 9 Dec 2022 15:22:29 -0800 Subject: [PATCH 2/4] format --- packages/kit/test/apps/options/test/test.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/kit/test/apps/options/test/test.js b/packages/kit/test/apps/options/test/test.js index 941a7fa91e72..8b96ea956189 100644 --- a/packages/kit/test/apps/options/test/test.js +++ b/packages/kit/test/apps/options/test/test.js @@ -12,11 +12,13 @@ test.describe('base path', () => { if (process.env.DEV) { // Vite's message expect(await html.text()).toBe( - 'The server is configured with a public base URL of /path-base - did you mean to visit /path-base/slash/ instead?' + 'The server is configured with a public base URL of /path-base - did you mean to visit /path-base/slash/ instead?' ); } else { // SvelteKit's message - expect(await html.text()).toBe('Not found (did you mean /path-base/slash/?)'); + expect(await html.text()).toBe( + 'Not found (did you mean /path-base/slash/?)' + ); } const plain = await request.get('/slash/'); From bd1032f53fab465e5980b07dffb4ea5caebffeb6 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Fri, 9 Dec 2022 15:27:22 -0800 Subject: [PATCH 3/4] standardize messages --- packages/kit/src/exports/vite/utils.js | 8 ++++++-- packages/kit/test/apps/options/test/test.js | 18 ++++++------------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/kit/src/exports/vite/utils.js b/packages/kit/src/exports/vite/utils.js index 4496c1408198..1d040ff31990 100644 --- a/packages/kit/src/exports/vite/utils.js +++ b/packages/kit/src/exports/vite/utils.js @@ -173,8 +173,12 @@ export function not_found(req, res, base) { if (type === 'text/html') { res.setHeader('Content-Type', 'text/html'); - res.end(`Not found (did you mean ${prefixed}?)`); + res.end( + `The server is configured with a public base URL of /path-base - did you mean to visit ${prefixed} instead?` + ); } else { - res.end(`Not found (did you mean ${prefixed}?)`); + res.end( + `The server is configured with a public base URL of /path-base - did you mean to visit ${prefixed} instead?` + ); } } diff --git a/packages/kit/test/apps/options/test/test.js b/packages/kit/test/apps/options/test/test.js index 8b96ea956189..588a7cbe558e 100644 --- a/packages/kit/test/apps/options/test/test.js +++ b/packages/kit/test/apps/options/test/test.js @@ -9,21 +9,15 @@ test.describe('base path', () => { test('serves a useful 404 when visiting unprefixed path', async ({ request }) => { const html = await request.get('/slash/', { headers: { Accept: 'text/html' } }); expect(html.status()).toBe(404); - if (process.env.DEV) { - // Vite's message - expect(await html.text()).toBe( - 'The server is configured with a public base URL of /path-base - did you mean to visit /path-base/slash/ instead?' - ); - } else { - // SvelteKit's message - expect(await html.text()).toBe( - 'Not found (did you mean /path-base/slash/?)' - ); - } + expect(await html.text()).toBe( + 'The server is configured with a public base URL of /path-base - did you mean to visit /path-base/slash/ instead?' + ); const plain = await request.get('/slash/'); expect(plain.status()).toBe(404); - expect(await plain.text()).toBe('Not found (did you mean /path-base/slash/?)'); + expect(await plain.text()).toBe( + 'The server is configured with a public base URL of /path-base - did you mean to visit /path-base/slash/ instead?' + ); }); test('serves /', async ({ page, javaScriptEnabled }) => { From 810450d73aec806d3ab5446a88341061069cd011 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Fri, 9 Dec 2022 15:28:13 -0800 Subject: [PATCH 4/4] changeset --- .changeset/clever-ducks-wave.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/clever-ducks-wave.md diff --git a/.changeset/clever-ducks-wave.md b/.changeset/clever-ducks-wave.md new file mode 100644 index 000000000000..e1773095058d --- /dev/null +++ b/.changeset/clever-ducks-wave.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +[fix] set Vite base URL