.js and .wasm files from dist/ served as text/html mime type
LeoniePhiline opened this issue · 3 comments
Hi!
Thanks for publishing your project starter! This is super nice to play with.
I ran into an issue quite quickly, though. The first time I ran the project with ./dev.sh
, stuff worked.
I then hit Ctrl+C
and tried ./prod.sh
. From then on, the .js
and .wasm
assets were served as text/html
mime type, which the browser of course rejects.
Do you have any clue what is happening there? It's very confusing, since it worked the first time around...
Update: Devtools show the JS and WASM file request being answered with the actual index.html content in prod mode.
Yeah indeed. So this is due to the addition of SpaRouter and its setup to server from /assets
. It does serve index.html
at the root but not any other files, such as the wasm modules. I've added SpaRouter due to a suggestion after writing the original article and did not test everything, my apologies.
The change needed to adjust for that: Trunk accepts an additional command line flag to set the path to serve from: https://trunkrs.dev/assets/#directives. So modifying the prod.sh
script as follows fixes the issue:
--- a/prod.sh
+++ b/prod.sh
@@ -3,7 +3,7 @@ set -euo pipefail
IFS=$'\n\t'
pushd frontend
-trunk build
+trunk build --public-url /assets/
popd
pushd server
I'll update the repo and article. Thank you for reporting the issue!
Thanks so much!