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

Use req.originalUrl for better Vite compatibility #7343

Merged
merged 4 commits into from Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion packages/kit/src/exports/node/index.js
Expand Up @@ -94,7 +94,8 @@ function get_raw_body(req, body_size_limit) {

/** @type {import('@sveltejs/kit/node').getRequest} */
export async function getRequest({ request, base, bodySizeLimit }) {
return new Request(base + request.url, {
// @ts-expect-error - the request may be a connect request
return new Request(base + (request.originalUrl || request.url), {
benmccann marked this conversation as resolved.
Show resolved Hide resolved
method: request.method,
headers: /** @type {Record<string, string>} */ (request.headers),
body: get_raw_body(request, bodySizeLimit)
Expand Down
6 changes: 3 additions & 3 deletions packages/kit/src/exports/vite/dev/index.js
Expand Up @@ -258,7 +258,7 @@ export async function dev(vite, vite_config, svelte_config) {
req.headers[':authority'] || req.headers.host
}`;

const decoded = decodeURI(new URL(base + req.url).pathname);
const decoded = decodeURI(new URL(base + req.originalUrl).pathname);

if (decoded.startsWith(assets)) {
const pathname = decoded.slice(assets.length);
Expand Down Expand Up @@ -295,7 +295,7 @@ export async function dev(vite, vite_config, svelte_config) {
req.headers[':authority'] || req.headers.host
}`;

const decoded = decodeURI(new URL(base + req.url).pathname);
const decoded = decodeURI(new URL(base + req.originalUrl).pathname);
const file = posixify(path.resolve(decoded.slice(1)));
const is_file = fs.existsSync(file) && !fs.statSync(file).isDirectory();
const allowed =
Expand All @@ -311,7 +311,7 @@ export async function dev(vite, vite_config, svelte_config) {
if (!decoded.startsWith(svelte_config.kit.paths.base)) {
return not_found(
res,
`Not found (did you mean ${svelte_config.kit.paths.base + req.url}?)`
`Not found (did you mean ${svelte_config.kit.paths.base + req.originalUrl}?)`
);
}

Expand Down