Skip to content
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

Fallback for multiple subdirectories #56

Open
stephanrenggli opened this issue Oct 14, 2022 · 4 comments
Open

Fallback for multiple subdirectories #56

stephanrenggli opened this issue Oct 14, 2022 · 4 comments

Comments

@stephanrenggli
Copy link

stephanrenggli commented Oct 14, 2022

I use goStatic in a docker/traefik setup where goStatic serves as errorpages and a catch-all. So any route that isn't matched by traefik will get routed to goStatic. The setup works well.

Traefik will handle: doesnotexist.example.com
The goStatic fallback will handle: doesnotexist.example.com/doesnotexist

The only case which currently isn't being handled nicely is: doesnotexist.example.com/doesnotexist/doesnotexist (or even more subdirs).
If there are multiple subdirectories the html page will be shown, but any css/js/images will fail to load.

Refused to apply style from 'https://doesnotexist.example.com/doesnotexist/css/404.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
Refused to execute script from 'https://doesnotexist.example.com/doesnotexist/js/tsparticles.bundle.min.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
Refused to execute script from 'https://doesnotexist.example.com/doesnotexist/js/404.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
Refused to apply style from 'https://doesnotexist.example.com/doesnotexist/css/404.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

I have tried both setting -fallback /index.html and -fallback index.html, the result seems to be the same.
My file structure inside the container looks as follows:

/srv/
├─ http/
│  ├─ css/
│  │  ├─ 404.css
│  ├─ images/
│  │  ├─ image.svg
│  ├─ js/
│  │  ├─ 404.js
│  │  ├─ tsparticles.bundle.min.js
│  ├─ index.html

Is there a way to redirect all requests to a specified path and not just one level of subdirectories?
Am I missing something else?

@PierreZ
Copy link
Owner

PierreZ commented Oct 17, 2022

Hi 👋
Thanks for the report, I don't think that is supported (yet) in goStatic. Would you like to contribute back this feature?

@stephanrenggli
Copy link
Author

Yes, will try to get it working on the weekend.

@PierreZ
Copy link
Owner

PierreZ commented Oct 18, 2022

Feel free to ping me if needed

@stephanrenggli
Copy link
Author

stephanrenggli commented Oct 20, 2022

So I tried a few things but I haven't found a solution that I think is good/works yet.
Here's the ideas I had:

  • Add another parameter (--redirect) which would allow to redirect everything to another URL or just the root of the current URL. But since goStatic only serves static files, redirect doesn't seem like the right idea. Also there would be the issue of circular redirects resulting in a TOO_MANY_REDIRECTS error.
  • Modify the request path to always serve the right file. Here I had the same problem of infinite redirects as I can't really hardcode any paths (in case css/js/images had subdirectories).
  • One option I can think of which I haven't tried yet would be to specify a directory with --fallback, scan the directory and only rewrite requests which don't match that structure.

But I feel like I may be way off path, so hints would be appreciated.

Edit: Might have a new idea:

Split requestPath at '/' and remove parts of the requestPath until the requestPath exists on the filesystem. This way nothing would have to be hardcoded and and as soon as the requested file exists it could be served.

Lets say the request is example.com/test/doesnotexist/css/404.css.
On the first iteration the file requested would be /test/doesnotexist/css/404.css.
On the second iteration the file requested would be /doesnotexist/css/404.css.
On the third iteration the file requested would be /css/404.css. This file actually exists and could be served.

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

No branches or pull requests

2 participants