Skip to content

Trailing slash normalization always redirects against root #13718

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

Open
HoldYourWaffle opened this issue Apr 16, 2025 · 3 comments · May be fixed by #13719
Open

Trailing slash normalization always redirects against root #13718

HoldYourWaffle opened this issue Apr 16, 2025 · 3 comments · May be fixed by #13719

Comments

@HoldYourWaffle
Copy link
Contributor

HoldYourWaffle commented Apr 16, 2025

Describe the bug

Related: #595 and #13702.

I need to integrate a SvelteKit app into an existing Express.js server at a dynamic base path. Based on #595 (comment) I assume this is intended to be supported through the kit.paths.relative option, but trailing slash normalization seems to assume SvelteKit is top dog and redirects against the root.

Standard static paths.base behavior (repro branch)

With a configuration like this:

const config = {
	kit: {
		adapter: adapterNode(),
		paths: {
			base: '/sveltekit',
			relative: true
		}
	}
}

...and integration into a custom server like this:

app.use(handler);

/sveltekit/sverdle/ is correctly redirected to /sveltekit/sverdle.

Dynamic paths.base attempt (repro branch)

With a configuration like this:

const config = {
	kit: {
		adapter: adapterNode(),
		paths: {
			relative: true
		}
	}
};

...and integration like this:

app.use('/sveltekit', handler);

/sveltekit/sverdle/ is incorrectly redirected to /sverdle.

Reproduction

HoldYourWaffle/sveltekit-express-dynamic-basepath, specifically repro--static-base and repro--dynamic-base.

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 16.98 GB / 31.81 GB
  Binaries:
    Node: 22.14.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.9.2 - C:\Program Files\nodejs\npm.CMD
    pnpm: 10.6.2 - ~\AppData\Local\pnpm\pnpm.CMD
  Browsers:
    Edge: Chromium (133.0.3065.69)
    Internet Explorer: 11.0.19041.4355

Severity

blocking all usage of SvelteKit

Additional Information

The Location header is allowed to be relative (MDN), so I think this should be an easy fix?™
Already working on a PR :)

@HoldYourWaffle HoldYourWaffle changed the title trailingSlash redirects against root instead of dynamic base trailingSlash always redirects against root Apr 16, 2025
@HoldYourWaffle HoldYourWaffle changed the title trailingSlash always redirects against root Trailing slash normalization always redirects against root Apr 16, 2025
@eltigerchino
Copy link
Member

eltigerchino commented Apr 18, 2025

I think the issue is that Express strips the mount path from the request URL, so if you have app.use('/sveltekit', handler) and a user navigates to /sveltekit/about , SvelteKit receives a different URL /about. While some routing features work, it breaks features such as redirects, links, URL information, etc. #7242 (comment) sums this up well

@HoldYourWaffle
Copy link
Contributor Author

Just to double check - are you sure you didn't mix this up with #13702? I agree that both are strongly related to #7242, but this specific problem has a much simpler solution (#13719).

@eltigerchino eltigerchino reopened this Apr 21, 2025
@eltigerchino
Copy link
Member

eltigerchino commented Apr 21, 2025

Sorry, after thinking about it more, the fix you've proposed should work even if the URL passed to SvelteKit is missing the base path. For example, if the requested path is /base-path/about and SvelteKit receives /about, it will result in the same relative redirect such as ../about/. While this doesn't fix all the base path issues that a fix for #7242 would, I think it could be useful to have these relative redirects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants