Skip to content

Commit 5dc7f9f

Browse files
authored
[fix] set Vite base URL (#8046)
1 parent 18e4e27 commit 5dc7f9f

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

.changeset/clever-ducks-wave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
[fix] set Vite base URL

packages/kit/src/exports/vite/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ function kit({ svelte_config }) {
253253
/** @type {import('vite').UserConfig} */
254254
const result = {
255255
appType: 'custom',
256-
base: './',
256+
base: svelte_config.kit.paths.base,
257257
build: {
258258
rollupOptions: {
259259
// Vite dependency crawler needs an explicit JS entry point

packages/kit/src/exports/vite/utils.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,12 @@ export function not_found(req, res, base) {
173173

174174
if (type === 'text/html') {
175175
res.setHeader('Content-Type', 'text/html');
176-
res.end(`Not found (did you mean <a href="${prefixed}">${prefixed}</a>?)`);
176+
res.end(
177+
`The server is configured with a public base URL of /path-base - did you mean to visit <a href="${prefixed}">${prefixed}</a> instead?`
178+
);
177179
} else {
178-
res.end(`Not found (did you mean ${prefixed}?)`);
180+
res.end(
181+
`The server is configured with a public base URL of /path-base - did you mean to visit ${prefixed} instead?`
182+
);
179183
}
180184
}

packages/kit/test/apps/options/source/template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
<body>
1010
<h1>I am in the template</h1>
1111
<div>%sveltekit.body%</div>
12-
<a href="/path-base/routing/link-outside-app-target/target">outside app target</a>
12+
<a href="/path-base/routing/link-outside-app-target/target/">outside app target</a>
1313
</body>
1414
</html>

packages/kit/test/apps/options/test/test.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ test.describe('base path', () => {
1010
const html = await request.get('/slash/', { headers: { Accept: 'text/html' } });
1111
expect(html.status()).toBe(404);
1212
expect(await html.text()).toBe(
13-
'Not found (did you mean <a href="/path-base/slash/">/path-base/slash/</a>?)'
13+
'The server is configured with a public base URL of /path-base - did you mean to visit <a href="/path-base/slash/">/path-base/slash/</a> instead?'
1414
);
1515

1616
const plain = await request.get('/slash/');
1717
expect(plain.status()).toBe(404);
18-
expect(await plain.text()).toBe('Not found (did you mean /path-base/slash/?)');
18+
expect(await plain.text()).toBe(
19+
'The server is configured with a public base URL of /path-base - did you mean to visit /path-base/slash/ instead?'
20+
);
1921
});
2022

2123
test('serves /', async ({ page, javaScriptEnabled }) => {
@@ -248,9 +250,9 @@ test.describe('Vite options', () => {
248250

249251
test.describe('Routing', () => {
250252
test('ignores clicks outside the app target', async ({ page }) => {
251-
await page.goto('/path-base/routing/link-outside-app-target/source');
253+
await page.goto('/path-base/routing/link-outside-app-target/source/');
252254

253-
await page.click('[href="/path-base/routing/link-outside-app-target/target"]');
255+
await page.click('[href="/path-base/routing/link-outside-app-target/target/"]');
254256
await expect(page.locator('h2')).toHaveText('target: 0');
255257
});
256258
});

0 commit comments

Comments
 (0)