-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
adapter-static: control “route.html
or route/index.html
” output separately from trailingSlash
option
#8770
Comments
For anyone else using Amazon S3 who wants paths without trailing slashes, I found a workaround:
The explicit content type metadata tells S3 how to serve this object, even without an extension. And since the build was configured to not use trailing slashes, the app’s client-side router also expects this slashless path. |
I just started using SvelteKit and had the same requirement |
@patrick-zippenfenig cheers for this, ran into the same issue. Though this does seem to break the relative paths of css files and other includes done in the html. Modified the script a bit to do what Geoffrey suggested |
One workaround is to structure your route such as |
I'm also running into this. @GeoffreyBooth's workaround does get me there, but I wouldn't consider it a solution because it requires saving the files without an extension in the project, e.g. I would love to see this addressed, happy to help test a fix (although testing is the straightforward part probably). |
I've found a solution that works for me. Unlike what @GeoffreyBooth claims in the original issue, paths without a trailing slash do work when static hosting on AWS, if your static site is built with So I guess specifically I disagree with two claims that @GeoffreyBooth makes:
and
The URL I hope this is helpful for anyone sharing this issue. |
My point is that most websites don't have paths that end in slashes, and such URLs look incorrect to average users. We want paths that don't end in slashes and that don't redirect to paths that end in slashes. |
My adapter-static s3 website was working through the direct *.s3-website.amazonaws.com url, but not through cloudfront. Here is what I ended up doing. In order to use the sveltekit build output without changing filenames, I used
and a cloudfront function on the distribution along the lines of
|
Describe the problem
I’m generating a static site that I’m putting in an Amazon S3 bucket where it gets served by CDN. My app has a file path like this:
build/foo/index.html
./foo
, with no trailing slash.My understanding of the docs is that the only option I have to influence this is
export const trailingSlash
in mysrc/routes/+layout.js
file. If I use eitherexport const trailingSlash = 'never'
or'ignore'
, the build command producesbuild/foo.html
. This doesn’t work for me, as my CDN doesn’t resolve/foo
to/foo.html
.This leaves
export const trailingSlash = 'always'
, which does cause the build command to produce my desired output ofbuild/foo/index.html
. But of course the point oftrailingSlash = 'always'
is to prevent a path of/foo
from working; it must be/foo/
. This isn’t the style we use for other URLs, and we want these URLs to be shareable without users needing to know that they shouldn’t strip off this unusual trailing slash. Or to boil down my feature request into a single sentence:adapter-static
to output “folder-based” routes (likesrc/routes/foo/+page.js
) as folders containingindex.html
files (likebuild/foo/index.html
) without also needing to make trailing slashes required.Describe the proposed solution
It seems to me like the simplest solution would be to create a new option to explicitly control HTML file output style (whether to output as
foo.html
or asfoo/index.html
), and if present it would override the choice determined bytrailingSlash
.Alternatives considered
I read #5334 and that issue seemed to get derailed into discussions of redirects and other aspects I’m not concerned with. I agree with the original poster’s feeling that it seems wrong that
trailingSlash
seems to collapse together two orthogonal options (how to treat trailing slashes in paths, and whether to outputfoo/+page.js
asfoo.html
orfoo/index.html
).After writing all of the above I just discovered #3801, where what I’m asking for seems to have been removed because the assumption was that there wouldn’t be static hosts out there that behave the way I’m describing, where a hosted
foo.html
isn’t accessible via/foo
andfoo/index.html
requires a trailing slash. These are configurable options; SvelteKit shouldn’t assume that no hosts support resolvingfoo/index.html
for/foo
(no trailing slash). Amazon S3’s website hosting default behavior is to redirect/foo
to/foo/
and serve the index file for/foo/
, but this can be changed.Importance
i cannot use SvelteKit without it
Additional Information
No response
The text was updated successfully, but these errors were encountered: