Unable to server emscripten generated HTML

1. The problem I’m having:

I have some C code that I compiled to WASM with emscripten, which also generates a javascript and HTML file to run the WASM file. I can serve the HTML file fine using python3’s http.server, but I’m having trouble with Caddy. I have 3 files: index.html, index.js and index.wasm.

When I browse to the URL the HTML loads, but I get a JS error in the console because the contents of index.html is returned instead of index.js when requested.

2. Error messages and/or full log output:

2025/02/26 01:32:59.503 INFO    using adjacent Caddyfile
2025/02/26 01:32:59.509 INFO    admin   admin endpoint started  {"address": "localhost:2019", "enforce_origin": false, "origins": ["//localhost:2019", "//[::1]:2019", "//127.0.0.1:2019"]}
2025/02/26 01:32:59.510 INFO    http    server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS        {"server_name": "srv0", "https_port": 443}
2025/02/26 01:32:59.510 INFO    http    enabling automatic HTTP->HTTPS redirects        {"server_name": "srv0"}
2025/02/26 01:32:59.511 INFO    http    enabling HTTP/3 listener        {"addr": ":443"}
2025/02/26 01:32:59.511 INFO    failed to sufficiently increase receive buffer size (was: 208 kiB, wanted: 2048 kiB, got: 416 kiB). See https://github.com/lucas-clemente/quic-go/wiki/UDP-Receive-Buffer-Size for details.
2025/02/26 01:32:59.512 INFO    http.log        server running  {"name": "srv0", "protocols": ["h1", "h2", "h3"]}
2025/02/26 01:32:59.512 INFO    http.log        server running  {"name": "remaining_auto_https_redirects", "protocols": ["h1", "h2", "h3"]}
2025/02/26 01:32:59.512 INFO    http    enabling automatic TLS certificate management   {"domains": ["example.com"]}
2025/02/26 01:32:59.513 INFO    autosaved config (load with --resume flag)      {"file": "/root/.config/caddy/autosave.json"}
2025/02/26 01:32:59.514 INFO    serving initial configuration
2025/02/26 01:32:59.514 INFO    tls.cache.maintenance   started background certificate maintenance      {"cache": "0xc0004fff10"}
2025/02/26 01:32:59.514 INFO    tls     cleaning storage unit   {"description": "FileStorage:/root/.local/share/caddy"}
2025/02/26 01:32:59.515 INFO    tls     finished cleaning storage units

3. Caddy version:

2.6.2

4. How I installed and ran Caddy:

Installed from apt on Debian 12

a. System environment:

Linux hostname 6.1.0-26-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.112-1 (2024-09-30) x86_64 GNU/Linux

b. Command:

caddy run

d. My complete Caddy config:

example.com {
        root * /root/
        header /index.js Content-Type application/javascript
        header /index.wasm Content-Type application/wasm
        header Access-Control-Allow-Origin *
        file_server

        try_files {path} /index.html
}

5. Links to relevant resources:

https://emscripten.org/docs/compiling/WebAssembly.html#compiler-output

This is too old. Don’t use Debian’s repo. Use ours.

Are they all next to each other at the root of the directory? I think they aren’t, which is why Caddy falls back to index.html.

If yes, enable debug option, access logs, and share them with a sample request.

1 Like