diff options
| author | Leonardo Bishop <me@leonardobishop.net> | 2026-01-07 23:39:53 +0000 |
|---|---|---|
| committer | Leonardo Bishop <me@leonardobishop.net> | 2026-01-07 23:39:53 +0000 |
| commit | 03cd6bdfbd473dba3f3dc50a1b15e389aac5bc70 (patch) | |
| tree | 5fea2b1840e298aaab953add749fb9226bd4a710 /web/web.go | |
Initial commit
Diffstat (limited to 'web/web.go')
| -rw-r--r-- | web/web.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/web/web.go b/web/web.go new file mode 100644 index 0000000..eaf03e8 --- /dev/null +++ b/web/web.go @@ -0,0 +1,39 @@ +package web + +import ( + "embed" + "html/template" + "net/http" + + "git.leonardobishop.net/instancer/pkg/deployer" + "git.leonardobishop.net/instancer/pkg/registry" + "git.leonardobishop.net/instancer/pkg/session" + "git.leonardobishop.net/instancer/web/handler" + "git.leonardobishop.net/instancer/web/middleware" +) + +//go:embed views +var views embed.FS + +func NewMux(registryClient *registry.RegistryClient, dockerDeployer *deployer.DockerDeployer) *http.ServeMux { + tmpl, err := template.ParseFS(views, "views/*.html") + if err != nil { + panic(err) + } + + mux := http.NewServeMux() + store := session.NewMemoryStore() + mustAuthenticate := middleware.MustAuthenticate(store) + + mux.HandleFunc("GET /auth", handler.GetAuth(tmpl)) + mux.HandleFunc("POST /auth", handler.PostAuth(tmpl, store)) + mux.HandleFunc("GET /logout", handler.GetLogout(store)) + + mux.HandleFunc("GET /", mustAuthenticate(handler.GetIndex(tmpl, registryClient))) + mux.HandleFunc("POST /deploy", mustAuthenticate(handler.PostDeploy(tmpl, dockerDeployer))) + mux.HandleFunc("GET /deploy/stream", mustAuthenticate(handler.DeploySSE(tmpl, registryClient, dockerDeployer))) + mux.HandleFunc("GET /instances", mustAuthenticate(handler.GetInstances(tmpl, dockerDeployer))) + mux.HandleFunc("POST /instances/{deployKey}/stop", mustAuthenticate(handler.PostStopInstance(tmpl, dockerDeployer))) + + return mux +} |
