summaryrefslogtreecommitdiff
path: root/internal/api/router.go
blob: 717236c01234c2b54d6faee22ba7b72223273d5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
}