mirror of
https://github.com/writefreely/writefreely
synced 2024-11-10 19:34:19 +00:00
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package writefreely
|
|
|
|
import (
|
|
"github.com/gorilla/mux"
|
|
"github.com/writeas/go-nodeinfo"
|
|
"github.com/writeas/web-core/log"
|
|
"github.com/writeas/writefreely/config"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
func initRoutes(handler *Handler, r *mux.Router, cfg *config.Config, db *datastore) {
|
|
isSingleUser := !cfg.App.MultiUser
|
|
|
|
hostSubroute := cfg.App.Host[strings.Index(cfg.App.Host, "://")+3:]
|
|
if isSingleUser {
|
|
hostSubroute = "{domain}"
|
|
} else {
|
|
if strings.HasPrefix(hostSubroute, "localhost") {
|
|
hostSubroute = "localhost"
|
|
}
|
|
}
|
|
|
|
if isSingleUser {
|
|
log.Info("Adding %s routes (single user)...", hostSubroute)
|
|
|
|
return
|
|
}
|
|
|
|
// Primary app routes
|
|
log.Info("Adding %s routes (multi-user)...", hostSubroute)
|
|
write := r.Host(hostSubroute).Subrouter()
|
|
|
|
// Federation endpoints
|
|
// nodeinfo
|
|
niCfg := nodeInfoConfig(cfg)
|
|
ni := nodeinfo.NewService(*niCfg, nodeInfoResolver{cfg, db})
|
|
write.HandleFunc(nodeinfo.NodeInfoPath, handler.LogHandlerFunc(http.HandlerFunc(ni.NodeInfoDiscover)))
|
|
write.HandleFunc(niCfg.InfoURL, handler.LogHandlerFunc(http.HandlerFunc(ni.NodeInfo)))
|
|
}
|