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

Support for relative base path to allow website to be served from different paths #866

Closed
wants to merge 10 commits into from

Conversation

wighawag
Copy link

@wighawag wighawag commented Sep 2, 2019

This PR add code to support relative base path so that a website can be hosted on any sub path, including IPFS gateways

This fixes : #746

Note that all url will finish with "/" as this is how ipfs gateways handle folder path

We could potentially add an option to specify a different behavior (remove the slash at the end) if we want but I ll leave that as a potential addition to be done in another PR.

Note that any attempt to access the website pages without a "/" at the end or by specifying "/index.html", will be redirected to the canonical url (with a "/")
This is achieved via location.replace

Note that it won't solve #863 though as filesystem access has its own problem, push state does not work there and this require to have index.html on every path.
This might be an extra option in the future if we can solve it.

Tests

get a sapper website from the get started guide
and execute the following

sapper export --relative-basepath

You can now serve it from any parent/grandparent folder

Or upload it on ipfs

An example can be found here on cloudflare gateway : https://cloudflare-ipfs.com/ipfs/QmNVTWGZ4qoW4DwiTze3icNJKhKBArR4HrCR1sapAFaPYg/

To show how the website can be loaded from different sub path I also added it to a ENS name. You can use a browser that support ENS or you can use the following link : https://wighawag.eth.link

You can also use a gateway like this : https://cloudflare-ipfs.com/ipns/wighawag.eth.link/

Note that I ll unpin the file and/or update that ENS domain in the future so appologies in advance for future readers :)

@wighawag
Copy link
Author

Did anyone look at the PR ?

I saw few people in the same situation as mine in the discord chat and having sapper website being able to be published on IPFS is I think a great feature that should not be discarded too quickly.

The changes are not invasive neither. I would love to get feedback if things can be improved so we can have that officially supported

Thanks

@thgh thgh mentioned this pull request Nov 9, 2019
@Clearwood
Copy link

I would really appreciate this becoming a part of the package.

@benmccann
Copy link
Member

We have several PRs dealing with base path (#1208 (comment)). Would #984 also solve your problem?

@benmccann
Copy link
Member

@wighawag thanks for your response in #1208 (comment). I'm responding here so as not to go off-topic discussing this PR in the comments of another PR

What I'm wondering is if #984 makes base optional, then can you just use relative URLs? Do you need to use basepath at all in that case? Using relative URLs instead of relative basepath would make the site work in IE

@spsaucier-bakkt
Copy link

This would be super useful - for instance, I am building for a client who will drop the folder wherever they want, and I have no control over where that will end up. It needs to be able to be dropped in anywhere on their server.

@benmccann
Copy link
Member

Thanks for putting together this PR! Sapper never had a good method of handling configuration, which made it difficult to know how to integrate this feature. However, that's been addressed in SvelteKit by adding a svelte.config.cjs file and adapters. I'm going to go ahead and close this PR since we won't be adding the feature to Sapper. You might like to check out SvelteKit instead. We'll be reviewing PRs for missing features there

@benmccann benmccann closed this Mar 24, 2021
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.

basepath calculated relative to nesting for IPFS hosting
4 participants