Skip to content

Commit

Permalink
Use req.originalUrl for better Vite compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Oct 21, 2022
1 parent 8e9d1a6 commit bd5dafb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/kit/src/exports/node/index.js
Original file line number Diff line number Diff line change
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), {
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
Original file line number Diff line number Diff line change
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

0 comments on commit bd5dafb

Please sign in to comment.