summaryrefslogtreecommitdiff
path: root/internal/api/router.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/api/router.go')
-rw-r--r--internal/api/router.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/internal/api/router.go b/internal/api/router.go
new file mode 100644
index 0000000..717236c
--- /dev/null
+++ b/internal/api/router.go
@@ -0,0 +1,30 @@
+package api
+
+import (
+ "net/http"
+
+ "vpnem/internal/rules"
+)
+
+func NewRouter(store *rules.Store) http.Handler {
+ h := NewHandler(store)
+ mux := http.NewServeMux()
+
+ mux.HandleFunc("GET /health", func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ w.Write([]byte(`{"status":"ok"}`))
+ })
+ mux.HandleFunc("GET /api/v1/servers", h.Servers)
+ mux.HandleFunc("GET /api/v1/ruleset/manifest", h.RuleSetManifest)
+ mux.HandleFunc("GET /api/v1/version", h.Version)
+
+ // Static file serving for .srs and .txt rule files
+ rulesFS := http.StripPrefix("/rules/", http.FileServer(http.Dir(store.RulesDir())))
+ mux.Handle("/rules/", rulesFS)
+
+ // Static file serving for client releases
+ releasesFS := http.StripPrefix("/releases/", http.FileServer(http.Dir(store.ReleasesDir())))
+ mux.Handle("/releases/", releasesFS)
+
+ return mux
+}