apps/feeds/routes.go 2.8 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
	mux.HandleFunc("GET /", a.indexHandler)
15
	mux.HandleFunc("GET /feeds", a.feedsExportHandler)
16
	mux.HandleFunc("GET /feed.xml", a.atomFeedHandler)
17
	mux.HandleFunc("GET /static/", web.EmbeddedHandler(appFS, "static"))
18
	darkmatter.Mount(mux, "/assets")
19
20
	requireSession := func(next http.HandlerFunc) http.HandlerFunc {
21
		return a.Sessions.RequireSession("/admin/login", next)
22
	}
23
	requireAPIAuth := func(next http.HandlerFunc) http.HandlerFunc {
24
		return auth.RequireBearerOrSession(a.Sessions, a.APIKey, next)
25
	}
26
27
	mux.HandleFunc("GET /admin/login", a.loginGetHandler)
28
	mux.HandleFunc("POST /admin/login", a.loginPostHandler)
29
	mux.HandleFunc("GET /admin/logout", a.logoutHandler)
30
	mux.HandleFunc("GET /admin", requireSession(a.adminHandler))
31
	mux.HandleFunc("POST /admin/add-feed", requireSession(a.addFeedHandler))
32
	mux.HandleFunc("POST /admin/feeds/{id}/delete", requireSession(a.deleteFeedHandler))
33
	mux.HandleFunc("POST /admin/feeds/{id}/category", requireSession(a.updateSubCategoryHandler))
34
	mux.HandleFunc("POST /admin/categories", requireSession(a.addCategoryHandler))
35
	mux.HandleFunc("POST /admin/categories/{id}/delete", requireSession(a.deleteCategoryHandler))
36
	mux.HandleFunc("POST /admin/import-opml", requireSession(a.importOPMLHandler))
37
	mux.HandleFunc("POST /admin/settings", requireSession(a.updateSettingsFormHandler))
38
	mux.HandleFunc("POST /admin/discover-feeds", requireSession(a.discoverFeedsHandler))
39
40
	mux.HandleFunc("GET /api/items", a.withCORS(a.listItemsAPI))
41
	mux.HandleFunc("POST /api/items/{id}/read", a.withCORS(requireAPIAuth(a.markItemReadAPI(true))))
42
	mux.HandleFunc("POST /api/items/{id}/unread", a.withCORS(requireAPIAuth(a.markItemReadAPI(false))))
43
	mux.HandleFunc("GET /api/subscriptions", a.withCORS(a.listSubscriptionsAPI))
44
	mux.HandleFunc("POST /api/subscriptions", a.withCORS(requireAPIAuth(a.createSubscriptionAPI)))
45
	mux.HandleFunc("PATCH /api/subscriptions/{id}", a.withCORS(requireAPIAuth(a.updateSubscriptionAPI)))
46
	mux.HandleFunc("DELETE /api/subscriptions/{id}", a.withCORS(requireAPIAuth(a.deleteSubscriptionAPI)))
47
	mux.HandleFunc("GET /api/categories", a.withCORS(a.listCategoriesAPI))
48
	mux.HandleFunc("POST /api/categories", a.withCORS(requireAPIAuth(a.createCategoryAPI)))
49
	mux.HandleFunc("DELETE /api/categories/{id}", a.withCORS(requireAPIAuth(a.deleteCategoryAPI)))
50
	mux.HandleFunc("POST /api/import/opml", a.withCORS(requireAPIAuth(a.importOPMLAPI)))
51
	mux.HandleFunc("GET /api/settings", a.withCORS(a.getSettingsAPI))
52
	mux.HandleFunc("PUT /api/settings", a.withCORS(requireAPIAuth(a.updateSettingsAPI)))
53
	mux.HandleFunc("POST /api/discover", a.withCORS(requireAPIAuth(a.discoverAPI)))
54
55
	return mux
56
}