apps/easel/routes.go 956 B 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
	mux.HandleFunc("GET /", a.indexHandler)
13
	mux.HandleFunc("GET /day/{date}", a.dayHandler)
14
	mux.HandleFunc("GET /archive", a.archiveHandler)
15
	mux.HandleFunc("GET /feed.xml", a.withCORS(a.atomFeedHandler))
16
	mux.HandleFunc("GET /api/today", a.withCORS(a.apiToday))
17
	mux.HandleFunc("GET /api/day/{date}", a.withCORS(a.apiDay))
18
	mux.HandleFunc("GET /api/archive", a.withCORS(a.apiArchive))
19
	mux.HandleFunc("GET /static/", web.EmbeddedHandler(appFS, "static"))
20
	darkmatter.Mount(mux, "/assets")
21
	return mux
22
}
23
24
func (a *App) withCORS(next http.HandlerFunc) http.HandlerFunc {
25
	return func(w http.ResponseWriter, r *http.Request) {
26
		w.Header().Set("Access-Control-Allow-Origin", "*")
27
		w.Header().Set("Access-Control-Allow-Methods", "GET")
28
		next(w, r)
29
	}
30
}