This commit is contained in:
2026-02-13 15:56:01 +03:00
parent 03d6c61587
commit 5a249ab510
7 changed files with 209 additions and 8 deletions

View File

@@ -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)
}