lorca
lorca copied to clipboard
Accessing nested directories
I am attempting to serve a Svelte site, and used the counter example as a starting point. I am able to use the development server with
ui.Load("http://localhost:5000")
but when I want to serve the static built files:
//go:embed frontend/public
var publicFolder embed.FS
...
go http.Serve(ln, http.FileServer(http.FS(publicFolder)))
ui.Load(fmt.Sprintf("http://%s/frontend/public/", ln.Addr()))
The browser can reach the index.html file but cannot reach the bundled assets in the <project>/frontend/public/build directory and the webview console gives the following error:
Refused to apply style from 'http://127.0.0.1:44369/global.css' because its MIME type ('text/plain') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
Refused to apply style from 'http://127.0.0.1:44369/build/bundle.css' because its MIME type ('text/plain') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
Failed to load resource: the server responded with a status of 404 (Not Found)
Failed to load resource: the server responded with a status of 404 (Not Found)
Refused to apply style from 'http://127.0.0.1:44369/global.css' because its MIME type ('text/plain') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
Refused to apply style from 'http://127.0.0.1:44369/build/bundle.css' because its MIME type ('text/plain') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
Sorry if Im missing something obvious, Im new to Lorca and Go. Thanks
My suggestion is to use some http framework/library like Gin-Gonic or Gorilla mux to serve the static files.
please refer it: https://github.com/eyotang/counter
subFs, _ := xfs.Sub(fs, "build")
go http.Serve(ln, http.FileServer(http.FS(subFs)))
ui.Load(fmt.Sprintf("http://%s", ln.Addr()))