Skip to content

Trailing slash normalization always redirects against root #13718

Open
@HoldYourWaffle

Description

@HoldYourWaffle

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 :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions