serveIndexHTML reads the SPA shell from the embedded bundle and returns it with a small runtime patch so the JS bundle knows which base path to use for API + WebSocket calls.
(w http.ResponseWriter)
| 1009 | // returns it with a small runtime patch so the JS bundle knows which |
| 1010 | // base path to use for API + WebSocket calls. |
| 1011 | func (s *Server) serveIndexHTML(w http.ResponseWriter) { |
| 1012 | f, err := s.Static.Open("index.html") |
| 1013 | if err != nil { |
| 1014 | http.NotFound(w, nil) |
| 1015 | return |
| 1016 | } |
| 1017 | defer f.Close() |
| 1018 | |
| 1019 | body, err := readAll(f) |
| 1020 | if err != nil { |
| 1021 | http.NotFound(w, nil) |
| 1022 | return |
| 1023 | } |
| 1024 | |
| 1025 | basePath := s.currentConfig().BasePath |
| 1026 | if basePath != "" { |
| 1027 | body = injectBasePathHint(body, basePath) |
| 1028 | } |
| 1029 | |
| 1030 | w.Header().Set("Content-Type", "text/html; charset=utf-8") |
| 1031 | w.Header().Set("Cache-Control", "no-cache") |
| 1032 | _, _ = w.Write(body) |
| 1033 | } |
| 1034 | |
| 1035 | func readAll(f fs.File) ([]byte, error) { |
| 1036 | buf := make([]byte, 0, 4*1024) |
no test coverage detected