Uploaded Media File Delete Update

This commit is contained in:
2026-02-22 13:04:04 -05:00
parent 3d936d8a6f
commit 3b4d5e4080
16 changed files with 701 additions and 451 deletions

View File

@@ -7,27 +7,34 @@ import (
"os"
"path/filepath"
"strings"
"sim-link-server/routes"
_ "github.com/mattn/go-sqlite3"
)
func loggingMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/api/") {
log.Printf("[%s] %s %s", r.RemoteAddr, r.Method, r.URL.Path)
}
next.ServeHTTP(w, r)
})
}
func main() {
initDBConnection()
defer db.Close()
syncResults()
// Handle API routes
http.HandleFunc("/api/simulations", getSimulations)
http.HandleFunc("/api/simulations/create", createSimulation)
http.HandleFunc("/api/simulations/", getSimulationDetails)
rt := routes.NewRouter(db)
rt.Register(http.DefaultServeMux)
// Serve the static files from results directory
resultsDir := "../results"
fsResults := http.FileServer(http.Dir(resultsDir))
http.Handle("/results/", http.StripPrefix("/results/", fsResults))
// Serve the static frontend with SPA fallback
frontendDir := "../build"
fsFrontend := http.FileServer(http.Dir(frontendDir))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
@@ -40,18 +47,12 @@ func main() {
fsFrontend.ServeHTTP(w, r)
})
fmt.Println("Server listening on port 5173")
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
// Wrap the default ServeMux with our logging middleware
fmt.Println("Server listening on port", port)
loggedMux := loggingMiddleware(http.DefaultServeMux)
log.Fatal(http.ListenAndServe("0.0.0.0:5173", loggedMux))
}
func loggingMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/api/") {
log.Printf("[%s] %s %s", r.RemoteAddr, r.Method, r.URL.Path)
}
next.ServeHTTP(w, r)
})
log.Fatal(http.ListenAndServe("0.0.0.0:"+port, loggedMux))
}