apps/quotes/routes.go 1.1 K raw
1
package main
2
3
import (
4
	"net/http"
5
6
	"github.com/stevedylandev/andromeda/pkg/darkmatter"
7
	"github.com/stevedylandev/andromeda/pkg/web"
8
)
9
10
func (a *App) routes() *http.ServeMux {
11
	mux := http.NewServeMux()
12
13
	requireSession := func(next http.HandlerFunc) http.HandlerFunc {
14
		return a.Sessions.RequireSession("/admin/login", next)
15
	}
16
17
	mux.HandleFunc("GET /", a.indexHandler)
18
	mux.HandleFunc("GET /random", a.randomHandler)
19
	mux.HandleFunc("GET /static/", web.EmbeddedHandler(appFS, "static"))
20
	darkmatter.Mount(mux, "/assets")
21
22
	mux.HandleFunc("GET /admin/login", a.loginGetHandler)
23
	mux.HandleFunc("POST /admin/login", a.loginPostHandler)
24
	mux.HandleFunc("GET /admin/logout", a.logoutHandler)
25
	mux.HandleFunc("GET /admin", requireSession(a.adminHandler))
26
	mux.HandleFunc("POST /admin/add", requireSession(a.adminAddQuote))
27
	mux.HandleFunc("POST /admin/quotes/{short_id}/delete", requireSession(a.adminDeleteQuote))
28
29
	mux.HandleFunc("GET /api/quotes", a.apiListQuotes)
30
	mux.HandleFunc("GET /api/quotes/today", a.apiQuoteOfTheDay)
31
	mux.HandleFunc("GET /api/quotes/random", a.apiRandomQuote)
32
	mux.HandleFunc("GET /api/quotes/{short_id}", a.apiGetQuote)
33
34
	return mux
35
}