Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Basepaths without --basepath #200

Merged
merged 11 commits into from
Mar 17, 2018
Merged

Basepaths without --basepath #200

merged 11 commits into from
Mar 17, 2018

Conversation

Rich-Harris
Copy link
Member

This is a much simpler solution to #180. Instead of specifying a --basepath flag, just mount the app on a path...

polka()
  .use('/custom-basepath', serve('assets'), sapper({routes}))
  .listen(process.env.PORT);

...and Sapper will figure out the rest. It will infer the basepath from the difference between req.url and req.originalUrl and assign it to req.baseUrl if that doesn't already exist (Express sets this value; Polka doesn't) and handle routing accordingly. It will also set a __SAPPER__.baseUrl property so that the client-side router knows what to do.

To export an app that has been mounted to a base path, you will still need to use --basepath:

npx sapper export --basepath custom-basepath

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant