I'm working on creating a sub-url for my file server in Golang.
The Golang function code I have is:
func main() {
fs := http.FileServer(http.Dir("../../dist/"))
http.Handle("/", fs)
http.Handle("/a/", http.StripPrefix("/a/", fs))
http.ListenAndServe(":8081", nil)
}
In the "../../dist/" directory, there is one index.html and several .wasm files. When I access :8081/, the file server works correctly. However, when I attempt to access :8081/a/, it finds the index.html but fails to load the .wasm files which are supposed to be loaded in HTML.
<html>
<head>
<link rel="preload" href="/start-4f9b00c561355aee_bg.wasm" as="fetch" type="application/wasm" crossorigin="">
<link rel="modulepreload" href="/start-4f9b00c561355aee.js">
</head>
<body>
<script type="module">
import init from '/start-4f9b00c561355aee.js';
init('/start-4f9b00c561355aee_bg.wasm');
</script>
</body>
</html>
I've tried adding http.StripPrefix (as seen in the code above), even adding Header().Set("content-type", "application/wasm"), but neither of these steps seems to allow /a/ to load properly.
Do I miss something? Thanks.