| package main |
|
|
| import ( |
| "log" |
| "net/http" |
| "net/http/httputil" |
| "net/url" |
| "os" |
| "strings" |
| ) |
|
|
| func main() { |
| |
| pythonTarget := "http://127.0.0.1:8001" |
| pythonURL, err := url.Parse(pythonTarget) |
| if err != nil { |
| log.Fatalf("Invalid Python target URL: %v", err) |
| } |
|
|
| |
| proxy := httputil.NewSingleHostReverseProxy(pythonURL) |
|
|
| |
| staticPath := "/usr/share/vchat/static" |
| fs := http.FileServer(http.Dir(staticPath)) |
|
|
| http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { |
| |
| |
| |
| 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 |
| } |
|
|
| |
| 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) |
| } |
| } |
|
|