InitRoutes adds dynamic routes for the given mux.Router.
(apper Apper, r *mux.Router)
| 36 | |
| 37 | // InitRoutes adds dynamic routes for the given mux.Router. |
| 38 | func 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 |
no test coverage detected