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 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/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/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..588a7cbe558e 100644 --- a/packages/kit/test/apps/options/test/test.js +++ b/packages/kit/test/apps/options/test/test.js @@ -10,12 +10,14 @@ test.describe('base path', () => { 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/?)' + '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 }) => { @@ -248,9 +250,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'); }); });