publish
This commit is contained in:
51
svc/main.go
51
svc/main.go
@@ -143,6 +143,7 @@ InitRoutes — FULL V3 (Method-aware) PERMISSION EDITION
|
||||
func InitRoutes(pgDB *sql.DB, mssql *sql.DB, ml *mailer.GraphMailer) *mux.Router {
|
||||
|
||||
r := mux.NewRouter()
|
||||
mountSPA(r)
|
||||
|
||||
/*
|
||||
===========================================================
|
||||
@@ -592,3 +593,53 @@ func main() {
|
||||
log.Println("✅ Server çalışıyor: http://localhost:8080")
|
||||
log.Fatal(http.ListenAndServe(":8080", handler))
|
||||
}
|
||||
|
||||
func mountSPA(m gorilla.Mux) {
|
||||
m.Group(func(r chi.Router) {
|
||||
r.NotFound(spaIndex)
|
||||
r.Get("/", spaIndex)
|
||||
})
|
||||
}
|
||||
|
||||
func spaIndex(w http.ResponseWriter, r *http.Request) {
|
||||
p := r.URL.Path
|
||||
|
||||
if r.URL.Path == "/logo.png" {
|
||||
_, err := os.Stat("./logo.png")
|
||||
if err == nil {
|
||||
http.ServeFile(w, r, "./logo.png")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(p, "/") {
|
||||
p = "/" + p
|
||||
r.URL.Path = p
|
||||
}
|
||||
p = path.Clean(p)
|
||||
if p == "/" {
|
||||
p = "index.html"
|
||||
}
|
||||
|
||||
if strings.HasPrefix(p, "/api") {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
name := path.Join(app.RUN.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))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if f.IsDir() {
|
||||
Forbidden(w, nil)
|
||||
return
|
||||
}
|
||||
|
||||
http.ServeFile(w, r, name)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user