You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 there's a bit of a snafu with trailing slashes on the base path.
Standard static paths.base behavior (repro branch)
/sveltekit is always redirected to /sveltekit/, regardless of trailingSlash configuration. This makes sense, because the trailing slash is necessary to resolve relative paths starting with ./ correctly.
This seems to be handled by this snippet that eventually ends up in build/server/index.js:
/sveltekit is no longer redirected to /sveltekit/, regardless of trailingSlash configuration. As expected this breaks basically everything with a relative path.
After some digging I realized that app.use strips out the provided prefix path, which causes url.pathname to be / in both situations, therefore the aforementioned check can't tell the difference.
I assume #7242 would solve this issue, since there's no need to pass a prefix path to app.use if paths.base can be provided at runtime.
Workaround
In my case I can just implement the redirect myself outside the context of app.use:
Describe the bug
Related: #595 and #7242.
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 there's a bit of a snafu with trailing slashes on the base path.Standard static
paths.base
behavior (repro branch)With a configuration like this:
...and integration into a custom server like this:
/sveltekit
is always redirected to/sveltekit/
, regardless oftrailingSlash
configuration. This makes sense, because the trailing slash is necessary to resolve relative paths starting with./
correctly.This seems to be handled by this snippet that eventually ends up in
build/server/index.js
:kit/packages/kit/src/runtime/server/respond.js
Lines 298 to 301 in 0b60ea7
Dynamic
paths.base
attempt (repro branch)With a configuration like this:
...and integration like this:
/sveltekit
is no longer redirected to/sveltekit/
, regardless oftrailingSlash
configuration. As expected this breaks basically everything with a relative path.Reproduction
HoldYourWaffle/sveltekit-express-dynamic-basepath, specifically
repro--static-base
andrepro--dynamic-base
.System Info
Severity
serious, but I can work around it
Additional Information
After some digging I realized that
app.use
strips out the provided prefix path, which causesurl.pathname
to be/
in both situations, therefore the aforementioned check can't tell the difference.I assume #7242 would solve this issue, since there's no need to pass a prefix path to
app.use
ifpaths.base
can be provided at runtime.Workaround
In my case I can just implement the redirect myself outside the context of
app.use
:The text was updated successfully, but these errors were encountered: