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