Remove the /
handler, and change the /mypath/
handler into the code below:
http.Handle("/mypath/", http.StripPrefix("/mypath/", http.FileServer(http.Dir("./my-project/dist/"))))
The http.StripPrefix()
function is used to remove the prefix of the requested path. On your current /mypath
handler, every request will be prefixed with /mypath/
. Take a look at the example below.
/mypath/index.html
/mypath/some/folder/style.css
...
If the requested URL path is not stripped, then (as per the above example) it'll point to the below respective locations, which is incorrect path, and will result in file not found
error.
./my-project/dist/mypath/index.html
./my-project/dist/mypath/some/folder/style.css
...
By stripping the /mypath
, it'll point to the below locations, the correct one.
./my-project/dist/index.html
./my-project/dist/some/folder/style.css
...