various fixes and liquid glass
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
@@ -12,10 +13,9 @@ import (
|
||||
)
|
||||
|
||||
func registerRoutes(r chi.Router) {
|
||||
// Serve static files from web/bulk-api-tester/static
|
||||
workDir, _ := os.Getwd()
|
||||
fs := http.FileServer(http.Dir(workDir + "/web/bulk-api-tester"))
|
||||
|
||||
webDir := filepath.Join(workDir, "web", "bulk-api-tester")
|
||||
|
||||
// API Endpoints
|
||||
r.Post("/api/proxy-request", proxyRequestHandler)
|
||||
r.Get("/api/collections", getCollectionsHandler)
|
||||
@@ -29,10 +29,49 @@ func registerRoutes(r chi.Router) {
|
||||
r.Post("/api/last-run", saveLastRunHandler)
|
||||
r.Get("/api/docs-data", getDocsDataHandler)
|
||||
|
||||
// Serve static assets and index.html
|
||||
r.Handle("/static/*", fs)
|
||||
// Direct routes for 3-file system
|
||||
r.Get("/", func(w http.ResponseWriter, req *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
http.ServeFile(w, req, filepath.Join(webDir, "index.html"))
|
||||
})
|
||||
r.Get("/index.html", func(w http.ResponseWriter, req *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
http.ServeFile(w, req, filepath.Join(webDir, "index.html"))
|
||||
})
|
||||
r.Get("/styles.css", func(w http.ResponseWriter, req *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/css; charset=utf-8")
|
||||
http.ServeFile(w, req, filepath.Join(webDir, "styles.css"))
|
||||
})
|
||||
r.Get("/style.css", func(w http.ResponseWriter, req *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/css; charset=utf-8")
|
||||
http.ServeFile(w, req, filepath.Join(webDir, "styles.css"))
|
||||
})
|
||||
r.Get("/app.js", func(w http.ResponseWriter, req *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/javascript; charset=utf-8")
|
||||
http.ServeFile(w, req, filepath.Join(webDir, "app.js"))
|
||||
})
|
||||
|
||||
// Static assets (displacement maps, specular maps, icons)
|
||||
r.Get("/assets/*", func(w http.ResponseWriter, req *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Cache-Control", "public, max-age=86400")
|
||||
fs := http.StripPrefix("/assets/", http.FileServer(http.Dir(filepath.Join(webDir, "assets"))))
|
||||
fs.ServeHTTP(w, req)
|
||||
})
|
||||
|
||||
// Legacy static asset compatibility aliases
|
||||
r.Get("/static/css/style.css", func(w http.ResponseWriter, req *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/css; charset=utf-8")
|
||||
http.ServeFile(w, req, filepath.Join(webDir, "styles.css"))
|
||||
})
|
||||
r.Get("/static/js/app.js", func(w http.ResponseWriter, req *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/javascript; charset=utf-8")
|
||||
http.ServeFile(w, req, filepath.Join(webDir, "app.js"))
|
||||
})
|
||||
|
||||
// Catch-all SPA handler
|
||||
r.Get("/*", func(w http.ResponseWriter, req *http.Request) {
|
||||
http.ServeFile(w, req, workDir+"/web/bulk-api-tester/index.html")
|
||||
http.ServeFile(w, req, filepath.Join(webDir, "index.html"))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -50,9 +89,9 @@ func main() {
|
||||
if scriptName != "" {
|
||||
r.Use(common.PrefixMiddleware(scriptName))
|
||||
}
|
||||
|
||||
|
||||
registerRoutes(r)
|
||||
|
||||
|
||||
slog.Info("starting bulk-api-tester", "port", port, "prefix", scriptName, "pid", os.Getpid())
|
||||
if err := http.ListenAndServe("127.0.0.1:"+port, r); err != nil {
|
||||
slog.Error("server failed", "error", err)
|
||||
|
||||
Reference in New Issue
Block a user