MCPcopy
hub / github.com/writefreely/writefreely / InitRoutes

Function InitRoutes

routes.go:38–220  ·  view source on GitHub ↗

InitRoutes adds dynamic routes for the given mux.Router.

(apper Apper, r *mux.Router)

Source from the content-addressed store, hash-verified

36
37// InitRoutes adds dynamic routes for the given mux.Router.
38func InitRoutes(apper Apper, r *mux.Router) *mux.Router {
39 // Create handler
40 handler := NewWFHandler(apper)
41
42 // Set up routes
43 hostSubroute := apper.App().cfg.App.Host[strings.Index(apper.App().cfg.App.Host, "://")+3:]
44 if apper.App().cfg.App.SingleUser {
45 hostSubroute = "{domain}"
46 } else {
47 if strings.HasPrefix(hostSubroute, "localhost") {
48 hostSubroute = "localhost"
49 }
50 }
51
52 if apper.App().cfg.App.SingleUser {
53 log.Info("Adding %s routes (single user)...", hostSubroute)
54 } else {
55 log.Info("Adding %s routes (multi-user)...", hostSubroute)
56 }
57
58 // Primary app routes
59 write := r.PathPrefix("/").Subrouter()
60
61 // Federation endpoint configurations
62 wf := webfinger.Default(wfResolver{apper.App().db, apper.App().cfg})
63 wf.NoTLSHandler = nil
64
65 // Federation endpoints
66 // host-meta
67 write.HandleFunc("/.well-known/host-meta", handler.Web(handleViewHostMeta, UserLevelReader))
68 // webfinger
69 write.HandleFunc(webfinger.WebFingerPath, handler.LogHandlerFunc(http.HandlerFunc(wf.Webfinger)))
70 // nodeinfo
71 niCfg := nodeInfoConfig(apper.App().db, apper.App().cfg)
72 ni := nodeinfo.NewService(*niCfg, nodeInfoResolver{apper.App().cfg, apper.App().db})
73 write.HandleFunc(nodeinfo.NodeInfoPath, handler.LogHandlerFunc(http.HandlerFunc(ni.NodeInfoDiscover)))
74 write.HandleFunc(niCfg.InfoURL, handler.LogHandlerFunc(http.HandlerFunc(ni.NodeInfo)))
75
76 // handle mentions
77 write.HandleFunc("/@/{handle}", handler.Web(handleViewMention, UserLevelReader))
78
79 configureSlackOauth(handler, write, apper.App())
80 configureWriteAsOauth(handler, write, apper.App())
81 configureGitlabOauth(handler, write, apper.App())
82 configureGenericOauth(handler, write, apper.App())
83 configureGiteaOauth(handler, write, apper.App())
84
85 // Set up dynamic page handlers
86 // Handle auth
87 auth := write.PathPrefix("/api/auth/").Subrouter()
88 if apper.App().cfg.App.OpenRegistration {
89 auth.HandleFunc("/signup", handler.All(apiSignup)).Methods("POST")
90 }
91 auth.HandleFunc("/login", handler.All(login)).Methods("POST")
92 auth.HandleFunc("/read", handler.WebErrors(handleWebCollectionUnlock, UserLevelNone)).Methods("POST")
93 auth.HandleFunc("/me", handler.All(handleAPILogout)).Methods("DELETE")
94
95 // Handle logged in user sections

Callers 2

serveActionFunction · 0.92
legacyActionsFunction · 0.92

Calls 15

NewWFHandlerFunction · 0.85
nodeInfoConfigFunction · 0.85
configureSlackOauthFunction · 0.85
configureWriteAsOauthFunction · 0.85
configureGitlabOauthFunction · 0.85
configureGenericOauthFunction · 0.85
configureGiteaOauthFunction · 0.85
RouteReadFunction · 0.85
RouteCollectionsFunction · 0.85
WebMethod · 0.80
LogHandlerFuncMethod · 0.80
AllMethod · 0.80

Tested by

no test coverage detected