fix: resolve forcetypeassert lint issues
This commit is contained in:
@@ -73,10 +73,17 @@ func (s *Server) SetupRoutes() {
|
|||||||
fileServer := http.FileServer(http.FS(distFS))
|
fileServer := http.FileServer(http.FS(distFS))
|
||||||
|
|
||||||
s.router.Get("/*", func(w http.ResponseWriter, r *http.Request) {
|
s.router.Get("/*", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
readFS, ok := distFS.(fs.ReadFileFS)
|
||||||
|
if !ok {
|
||||||
|
http.Error(w, "internal error", http.StatusInternalServerError)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Try to serve the file; if not found, serve index.html for SPA routing
|
// Try to serve the file; if not found, serve index.html for SPA routing
|
||||||
f, err := distFS.(fs.ReadFileFS).ReadFile(r.URL.Path[1:])
|
f, err := readFS.ReadFile(r.URL.Path[1:])
|
||||||
if err != nil || len(f) == 0 {
|
if err != nil || len(f) == 0 {
|
||||||
indexHTML, _ := distFS.(fs.ReadFileFS).ReadFile("index.html")
|
indexHTML, _ := readFS.ReadFile("index.html")
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
|
|||||||
Reference in New Issue
Block a user