I deployed a new react.js application in /opt/fe/website (/demo/), but it is giving error messages. It is working on localhost.
Since the error message is about wrong mimetype, I tried to define them manually, but in that case, caddy does not start, without error details.
Where can I define the mime types ?
Or is something else causing the issue ?
Job for caddy.service failed because the control process exited with error code.
See “systemctl status caddy.service” and “journalctl -xeu caddy.service” for details.
Browser error:
“Failed to load module script: Expected a JavaScript-or-Wasm module script but the server responded with a MIME type of “text/html”. assets/index-BGSeMjDe.js
There’s no directive mime in Caddy. You’ll need to use the header directive. I also recommend you go through the matchers section on the Caddyfile Concepts page.
The browser seems to be complaining about a JavaScript file, but your attempt is with .css extension. Ensure you have mailcap installed, as it’s the package providing the OS the database of mimetypes.
That’s not the official documentation site. Please refer to our official site. The linked page is a copy of our v1 documentation. Caddy is not at v2.10.2.
This sounds like you should resolve it with mailcap first. Install the mailcap package first. If that doesn’t solve it, you can do this:
It took some time since the server had also a problem with the filesystem.
However, also after adding “mailcap” package and adding the header informatin, the problem still persists.
I think it can be a wrong error message.
But not sure what it could be.
Loading the module from “AI Demo was blocked due to an unsupported MIME type (“text/html”).
demo
Failed to load the module with the source “AI Demo. demo:19:76
The stylesheet AI Demo was not loaded because its MIME type, “text/html,” is not “text/css.”
Now I found the real problem it seems.
The subpath is not provided at all (got the hint from Claude).
And then it is redirecting to the root page, which delivers an html file instead of css or javascript.
I commented the line with try_files {path} /index.html
And with /demo/index.html it redirects to the root index.html instead of the other webpage.
I made /demo first, but I am not sure if Caddy cares about order.
How can I change that, so it will stick with the second webpage in /opt/fe/website ?
Caddy serves the index.html, but no css or js file, it seems not to find them. But the path is correct, and the file existd.
Redirect in sense it does not find the file (404), and falls back to index.html. That results in Mime error, since the browser wants to load css/js file, but gets html instead.
From my point this is a bug in Caddy, 404 should not fall back to html file.
Caddy sorts by path matcher length ? Can you pls point to the documentation or explain ?
It is not a bug. You used try_files. That’s what try_files entire purpose. See the linked docs. What’s the directory and file structure in each of your roots? Is the request path we’re seeing here the full path?
It is explained in detail under Sorting Algorithm section