apps/bookmarks/routes.go 1.4 K raw
1
package main
2
3
import (
4
	"net/http"
5
6
	"github.com/stevedylandev/andromeda/pkg/auth"
7
	"github.com/stevedylandev/andromeda/pkg/darkmatter"
8
	"github.com/stevedylandev/andromeda/pkg/web"
9
)
10
11
func (a *App) routes() *http.ServeMux {
12
	mux := http.NewServeMux()
13
14
	requireSession := func(next http.HandlerFunc) http.HandlerFunc {
15
		return a.Sessions.RequireSession("/login", next)
16
	}
17
	requireAPIKey := func(next http.HandlerFunc) http.HandlerFunc {
18
		return auth.RequireAPIKey(a.APIKey, next)
19
	}
20
21
	mux.HandleFunc("GET /", a.indexHandler)
22
	mux.HandleFunc("GET /login", a.loginGetHandler)
23
	mux.HandleFunc("POST /login", a.loginPostHandler)
24
	mux.HandleFunc("GET /logout", a.logoutHandler)
25
	mux.HandleFunc("GET /admin", requireSession(a.adminHandler))
26
	mux.HandleFunc("POST /admin/categories", requireSession(a.adminAddCategory))
27
	mux.HandleFunc("POST /admin/categories/{short_id}/delete", requireSession(a.adminDeleteCategory))
28
	mux.HandleFunc("POST /admin/categories/{short_id}/move/{dir}", requireSession(a.adminMoveCategory))
29
	mux.HandleFunc("POST /admin/links", requireSession(a.adminAddLink))
30
	mux.HandleFunc("POST /admin/links/{short_id}/delete", requireSession(a.adminDeleteLink))
31
32
	mux.HandleFunc("GET /api/categories", a.apiListCategories)
33
	mux.HandleFunc("GET /api/links", a.apiListLinks)
34
	mux.HandleFunc("POST /api/links", requireAPIKey(a.apiCreateLink))
35
36
	mux.HandleFunc("GET /static/", web.EmbeddedHandler(appFS, "static"))
37
	darkmatter.Mount(mux, "/assets")
38
	return mux
39
}