Skip to content

Commit

Permalink
[fix] set Vite base URL (#8046)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Dec 10, 2022
1 parent 18e4e27 commit 5dc7f9f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-ducks-wave.md
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[fix] set Vite base URL
2 changes: 1 addition & 1 deletion packages/kit/src/exports/vite/index.js
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions packages/kit/src/exports/vite/utils.js
Expand Up @@ -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 <a href="${prefixed}">${prefixed}</a>?)`);
res.end(
`The server is configured with a public base URL of /path-base - did you mean to visit <a href="${prefixed}">${prefixed}</a> 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?`
);
}
}
2 changes: 1 addition & 1 deletion packages/kit/test/apps/options/source/template.html
Expand Up @@ -9,6 +9,6 @@
<body>
<h1>I am in the template</h1>
<div>%sveltekit.body%</div>
<a href="/path-base/routing/link-outside-app-target/target">outside app target</a>
<a href="/path-base/routing/link-outside-app-target/target/">outside app target</a>
</body>
</html>
10 changes: 6 additions & 4 deletions packages/kit/test/apps/options/test/test.js
Expand Up @@ -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 <a href="/path-base/slash/">/path-base/slash/</a>?)'
'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?'
);

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 }) => {
Expand Down Expand Up @@ -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');
});
});

0 comments on commit 5dc7f9f

Please sign in to comment.