2018-10-15 20:44:15 +02:00
|
|
|
package writefreely
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gorilla/mux"
|
2018-10-18 00:57:37 +02:00
|
|
|
"github.com/writeas/go-nodeinfo"
|
2018-10-15 20:44:15 +02:00
|
|
|
"github.com/writeas/web-core/log"
|
|
|
|
"github.com/writeas/writefreely/config"
|
2018-10-18 00:57:37 +02:00
|
|
|
"net/http"
|
2018-10-15 20:44:15 +02:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2018-10-17 04:31:27 +02:00
|
|
|
func initRoutes(handler *Handler, r *mux.Router, cfg *config.Config, db *datastore) {
|
2018-10-15 20:44:15 +02:00
|
|
|
isSingleUser := !cfg.App.MultiUser
|
|
|
|
|
|
|
|
// Write.as router
|
|
|
|
hostSubroute := cfg.Server.Host[strings.Index(cfg.Server.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)
|
2018-10-18 00:57:37 +02:00
|
|
|
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)))
|
2018-10-15 20:44:15 +02:00
|
|
|
}
|