1. Caddy version (caddy version
):
V2
2. How I run Caddy:
Docker image
a. System environment:
Dev system Win 10, final deployment on Ubuntu
b. Command:
docker build .
docker run -p 80:80
(note that this is on test system)
c. Service/unit/compose file:
(Dockerfile)
FROM caddy:2.0.0
COPY Caddyfile /etc/caddy/Caddyfile
COPY dist /var/html/www
d. My complete Caddyfile or JSON config:
:80 {
root * /var/html/www
encode gzip
@work {
path /work/*
}
@app {
path /work/app.min.js
}
@best {
path /work/test.js
}
@fonts {
path /work/fonts.css
}
rewrite @app /app.min.js
rewrite @work index.html
rewrite @fonts /fonts.css
rewrite @best /test.js
file_server
}
3. The problem I’m having:
I’m currently building what is intended to be a single page site using the History api using Docker. It’s just a frontend site, no backend stack involved but I need to rewrite some paths and I’m having a bit of trouble.
For those unfamiliar, essentially the goal is
- All paths should load
/
under the hood while keeping the url intact - Static files paths should still work as expected rewrite or no rewrite
After a lot of trial and error the above Caddyfile seems to have gotten me most of the way there, but I am running into the most bizarre issue at the moment.
When you navigate to /
, everything loads and functions as expected. However, on any other path, while as far as I can tell, things load correctly as well, my javascript doesn’t fire. It looks like the correct HTML is there, the site javascript appears to have loaded as well, things just don’t start for whatever reason.
Not sure if it will help or not, but I have noticed some other oddities as well.
-
Adding a second Javascript file seems to break things too(reflected above with test.js). The browser is somehow returning the the home page html instead of the javascript in spite of the same rewrite being done like on the @app route. The main Javascript file referenced by the @app route is being interpreted correctly as Javascript. Both test.js and app.min.js are at the root of the site folder.
-
My main browser is Firefox and I noticed in devtools, network tab, under the “initiator” column, the value listed is “browsing-content.js:” instead of “document” like when on the home page.
To clarify - I do not intend to use the above Caddyfile in production; I know it’s messy haha. It is purely just for me to learn and test stuff out.
4. Error messages and/or full log output:
N/A
5. What I already tried:
-
For the line
rewrite @work index.html
, I’ve tried/
and/index.html
as well -
Looking through documentation to see if I’m missing something.
-
tried seeing if changing the order of the
file_server
directive has any impact. -
Try adding a second Javascript file that just writes to the console but that is getting interpreted as HTML for some reason even though the other Javascript file on the page was properly parsed as javascript
6. Links to relevant resources:
N/A
Any help is appreciated! If I’m completely going in the wrong direction, please don’t hesitate to point that out. Will keep trying in the meantime!