Merge remote-tracking branch 'origin/master'
# Conflicts: # ui/src/pages/OrderList.vue
This commit is contained in:
36
svc/main.go
36
svc/main.go
@@ -12,7 +12,10 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/joho/godotenv"
|
||||
@@ -594,14 +597,13 @@ func main() {
|
||||
log.Fatal(http.ListenAndServe(":8080", handler))
|
||||
}
|
||||
|
||||
func mountSPA(m gorilla.Mux) {
|
||||
m.Group(func(r chi.Router) {
|
||||
r.NotFound(spaIndex)
|
||||
r.Get("/", spaIndex)
|
||||
})
|
||||
func mountSPA(r *mux.Router) {
|
||||
r.NotFoundHandler = http.HandlerFunc(spaIndex)
|
||||
r.HandleFunc("/", spaIndex).Methods(http.MethodGet)
|
||||
}
|
||||
|
||||
func spaIndex(w http.ResponseWriter, r *http.Request) {
|
||||
uiDir := uiRootDir()
|
||||
p := r.URL.Path
|
||||
|
||||
if r.URL.Path == "/logo.png" {
|
||||
@@ -626,20 +628,38 @@ func spaIndex(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
name := path.Join(app.RUN.UiDir, filepath.FromSlash(p))
|
||||
name := path.Join(uiDir, filepath.FromSlash(p))
|
||||
|
||||
f, err := os.Stat(name)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
http.ServeFile(w, r, fmt.Sprintf("%s/index.html", app.RUN.UiDir))
|
||||
http.ServeFile(w, r, filepath.Join(uiDir, "index.html"))
|
||||
return
|
||||
}
|
||||
|
||||
http.Error(w, "internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if f.IsDir() {
|
||||
Forbidden(w, nil)
|
||||
http.Error(w, "forbidden", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
http.ServeFile(w, r, name)
|
||||
}
|
||||
|
||||
func uiRootDir() string {
|
||||
if d := strings.TrimSpace(os.Getenv("UI_DIR")); d != "" {
|
||||
return d
|
||||
}
|
||||
|
||||
candidates := []string{"../ui/dist", "./ui/dist"}
|
||||
for _, d := range candidates {
|
||||
if fi, err := os.Stat(d); err == nil && fi.IsDir() {
|
||||
return d
|
||||
}
|
||||
}
|
||||
|
||||
return "../ui/dist"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user