@sveltejs/kit 1.2.5 → 1.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -364,10 +364,13 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
364
364
|
/** @type {function} */ (middleware.handle).name === 'viteServeStaticMiddleware'
|
|
365
365
|
);
|
|
366
366
|
|
|
367
|
+
// Vite will give a 403 on URLs like /test, /static, and /package.json preventing us from
|
|
368
|
+
// serving routes with those names. See https://github.com/vitejs/vite/issues/7363
|
|
367
369
|
remove_static_middlewares(vite.middlewares);
|
|
368
370
|
|
|
369
371
|
vite.middlewares.use(async (req, res) => {
|
|
370
372
|
// Vite's base middleware strips out the base path. Restore it
|
|
373
|
+
const original_url = req.url;
|
|
371
374
|
req.url = req.originalUrl;
|
|
372
375
|
try {
|
|
373
376
|
const base = `${vite.config.server.https ? 'https' : 'http'}://${
|
|
@@ -375,13 +378,14 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
375
378
|
}`;
|
|
376
379
|
|
|
377
380
|
const decoded = decodeURI(new URL(base + req.url).pathname);
|
|
378
|
-
const file = posixify(path.resolve(decoded.slice(1)));
|
|
381
|
+
const file = posixify(path.resolve(decoded.slice(svelte_config.kit.paths.base.length + 1)));
|
|
379
382
|
const is_file = fs.existsSync(file) && !fs.statSync(file).isDirectory();
|
|
380
383
|
const allowed =
|
|
381
384
|
!vite_config.server.fs.strict ||
|
|
382
385
|
vite_config.server.fs.allow.some((dir) => file.startsWith(dir));
|
|
383
386
|
|
|
384
387
|
if (is_file && allowed) {
|
|
388
|
+
req.url = original_url;
|
|
385
389
|
// @ts-expect-error
|
|
386
390
|
serve_static_middleware.handle(req, res);
|
|
387
391
|
return;
|
|
@@ -110,6 +110,9 @@ export async function respond(request, options, manifest, state) {
|
|
|
110
110
|
/** @type {Record<string, string>} */
|
|
111
111
|
const headers = {};
|
|
112
112
|
|
|
113
|
+
/** @type {Record<string, import('./page/types').Cookie>} */
|
|
114
|
+
let cookies_to_add = {};
|
|
115
|
+
|
|
113
116
|
/** @type {import('types').RequestEvent} */
|
|
114
117
|
const event = {
|
|
115
118
|
// @ts-expect-error `cookies` and `fetch` need to be created after the `event` itself
|
|
@@ -221,6 +224,7 @@ export async function respond(request, options, manifest, state) {
|
|
|
221
224
|
trailing_slash ?? 'never'
|
|
222
225
|
);
|
|
223
226
|
|
|
227
|
+
cookies_to_add = new_cookies;
|
|
224
228
|
event.cookies = cookies;
|
|
225
229
|
event.fetch = create_fetch({ event, options, manifest, state, get_cookie_header });
|
|
226
230
|
|
|
@@ -237,7 +241,7 @@ export async function respond(request, options, manifest, state) {
|
|
|
237
241
|
response.headers.set(key, /** @type {string} */ (value));
|
|
238
242
|
}
|
|
239
243
|
|
|
240
|
-
add_cookies_to_headers(response.headers, Object.values(
|
|
244
|
+
add_cookies_to_headers(response.headers, Object.values(cookies_to_add));
|
|
241
245
|
|
|
242
246
|
if (state.prerendering && event.route.id !== null) {
|
|
243
247
|
response.headers.set('x-sveltekit-routeid', encodeURI(event.route.id));
|
|
@@ -293,11 +297,11 @@ export async function respond(request, options, manifest, state) {
|
|
|
293
297
|
return response;
|
|
294
298
|
} catch (e) {
|
|
295
299
|
if (e instanceof Redirect) {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
300
|
+
const response = is_data_request
|
|
301
|
+
? redirect_json_response(e)
|
|
302
|
+
: redirect_response(e.status, e.location);
|
|
303
|
+
add_cookies_to_headers(response.headers, Object.values(cookies_to_add));
|
|
304
|
+
return response;
|
|
301
305
|
}
|
|
302
306
|
return await handle_fatal_error(event, options, e);
|
|
303
307
|
}
|