Skip to content
10 changes: 9 additions & 1 deletion packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,17 +624,25 @@ function kit({ svelte_config }) {
*/
configurePreviewServer(vite) {
// generated client assets and the contents of `static`
// should we use Vite's built-in asset server for this?
// we would need to set the outDir to do so
const { paths } = svelte_config.kit;
const assets = paths.assets ? SVELTE_KIT_ASSETS : paths.base;
vite.middlewares.use(
scoped(
assets,
sirv(join(svelte_config.kit.outDir, 'output/client'), {
setHeaders: (res, pathname) => {
// only apply to immutable directory, not e.g. version.json
if (pathname.startsWith(`/${svelte_config.kit.appDir}/immutable`)) {
res.setHeader('cache-control', 'public,max-age=31536000,immutable');
}
if (vite_config.preview.cors) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader(
'Access-Control-Allow-Headers',
'Origin, Content-Type, Accept, Range'
);
}
}
})
)
Expand Down
5 changes: 2 additions & 3 deletions packages/kit/src/exports/vite/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export async function preview(vite, vite_config, svelte_config) {
}

const { paths } = svelte_config.kit;
const base = paths.base;
const assets = paths.assets ? SVELTE_KIT_ASSETS : paths.base;

const protocol = vite_config.preview.https ? 'https' : 'http';
Expand Down Expand Up @@ -125,11 +124,11 @@ export async function preview(vite, vite_config, svelte_config) {
// SSR
vite.middlewares.use(async (req, res) => {
const host = req.headers['host'];

req.url = req.originalUrl;
let request;
try {
request = await getRequest({
base: new URL(base, `${protocol}://${host}`).href,
base: `${protocol}://${host}`,
request: req
});
} catch (/** @type {any} */ err) {
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/test/apps/options-2/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ test.describe('Service worker', () => {
});

expect(self.base).toBe('/basepath');
expect(self.build[0]).toMatch(/\/basepath\/_app\/immutable\/entry\/start\.[\w-]+\.js/);
expect(self.build?.[0]).toMatch(/\/basepath\/_app\/immutable\/entry\/start\.[\w-]+\.js/);
});

test('does not register /basepath/service-worker.js', async ({ page }) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/kit/test/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'node:fs';
import path from 'node:path';
import http from 'node:http';
import { test as base, devices } from '@playwright/test';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { test as base, devices } from '@playwright/test';

export const test = base.extend({
app: async ({ page }, use) => {
Expand Down Expand Up @@ -73,7 +73,7 @@ export const test = base.extend({
/** @param {string} selector */
async function in_view(selector) {
const box = await page.locator(selector).boundingBox();
const view = await page.viewportSize();
const view = page.viewportSize();
return box && view && box.y < view.height && box.y + box.height > 0;
}

Expand Down