VFacts / main.go
Keqing Li
Final verified deployment for HF Space
c9f5b32
package main
import (
"log"
"net/http"
"net/http/httputil"
"net/url"
"os"
"strings"
)
func main() {
// Target Python FastAPI server (running locally in the container)
pythonTarget := "http://127.0.0.1:8001"
pythonURL, err := url.Parse(pythonTarget)
if err != nil {
log.Fatalf("Invalid Python target URL: %v", err)
}
// Create Reverse Proxy
proxy := httputil.NewSingleHostReverseProxy(pythonURL)
// FIXED: Point to the new location safe from Docker Volumes
staticPath := "/usr/share/vchat/static"
fs := http.FileServer(http.Dir(staticPath))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
// Check if request is for the API
// Added /queue to the list so uploads and list fetches work
// ADDED: /workflow to fix JSON parse error in frontend
if strings.HasPrefix(r.URL.Path, "/process") ||
strings.HasPrefix(r.URL.Path, "/label_video") ||
strings.HasPrefix(r.URL.Path, "/batch_label") ||
strings.HasPrefix(r.URL.Path, "/model-architecture") ||
strings.HasPrefix(r.URL.Path, "/download-dataset") ||
strings.HasPrefix(r.URL.Path, "/extension") ||
strings.HasPrefix(r.URL.Path, "/manage") ||
strings.HasPrefix(r.URL.Path, "/workflow") ||
strings.HasPrefix(r.URL.Path, "/queue") {
log.Printf("Proxying %s to Python Backend...", r.URL.Path)
proxy.ServeHTTP(w, r)
return
}
// Check if file exists in static dir, otherwise serve index.html (SPA Routing)
path := staticPath + r.URL.Path
if _, err := os.Stat(path); os.IsNotExist(err) {
http.ServeFile(w, r, staticPath+"/index.html")
return
}
fs.ServeHTTP(w, r)
})
port := "8000"
log.Printf("vChat Modern Server listening on port %s", port)
log.Printf("Serving static files from %s", staticPath)
if err := http.ListenAndServe(":"+port, nil); err != nil {
log.Fatal(err)
}
}