Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] set Vite base URL #8046

Merged
merged 4 commits into from Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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');
});
});