From 74b542023fb84dda26822a57ce497e45a824c9c7 Mon Sep 17 00:00:00 2001 From: Ross Trottier Date: Thu, 22 Aug 2024 13:53:27 -0600 Subject: [PATCH] apps endpoint --- cmd/web/handlers.go | 14 ++++++++++++++ cmd/web/routes.go | 1 + 2 files changed, 15 insertions(+) diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go index ef8b129..156ec9a 100644 --- a/cmd/web/handlers.go +++ b/cmd/web/handlers.go @@ -1,6 +1,7 @@ package main import ( + "encoding/json" "net/http" ) @@ -22,4 +23,17 @@ func (app *application) notFound(writer http.ResponseWriter, request *http.Reque func (app *application) vpn(writer http.ResponseWriter, request *http.Request) { app.render(writer, request, http.StatusOK, "vpn.tmpl.html", templateData{}) +} + +func (app *application) appList(writer http.ResponseWriter, request *http.Request) { + appLinks := getAppLinks(app.tier, app.domain) + writer.Header().Set("Content-Type", "application/json") + data, err := json.Marshal(appLinks) + + if err != nil { + app.serverError(writer, request, err) + return + } + + writer.Write(data) } \ No newline at end of file diff --git a/cmd/web/routes.go b/cmd/web/routes.go index 61624cc..51d9440 100644 --- a/cmd/web/routes.go +++ b/cmd/web/routes.go @@ -11,6 +11,7 @@ func (app *application) routes() *http.ServeMux { mux.HandleFunc("GET /{$}", app.home) mux.HandleFunc("GET /", app.notFound) mux.HandleFunc("GET /vpn/{$}", app.vpn) + mux.HandleFunc("GET /apps/{$}", app.appList) return mux } \ No newline at end of file