A clean, Markdown-based publishing platform made for writers. Write together, and build a community. https://writefreely.org
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 

41 řádky
1.1 KiB

  1. package writefreely
  2. import (
  3. "github.com/gorilla/mux"
  4. "github.com/writeas/go-nodeinfo"
  5. "github.com/writeas/web-core/log"
  6. "github.com/writeas/writefreely/config"
  7. "net/http"
  8. "strings"
  9. )
  10. func initRoutes(handler *Handler, r *mux.Router, cfg *config.Config, db *datastore) {
  11. isSingleUser := !cfg.App.MultiUser
  12. hostSubroute := cfg.App.Host[strings.Index(cfg.App.Host, "://")+3:]
  13. if isSingleUser {
  14. hostSubroute = "{domain}"
  15. } else {
  16. if strings.HasPrefix(hostSubroute, "localhost") {
  17. hostSubroute = "localhost"
  18. }
  19. }
  20. if isSingleUser {
  21. log.Info("Adding %s routes (single user)...", hostSubroute)
  22. return
  23. }
  24. // Primary app routes
  25. log.Info("Adding %s routes (multi-user)...", hostSubroute)
  26. write := r.Host(hostSubroute).Subrouter()
  27. // Federation endpoints
  28. // nodeinfo
  29. niCfg := nodeInfoConfig(cfg)
  30. ni := nodeinfo.NewService(*niCfg, nodeInfoResolver{cfg, db})
  31. write.HandleFunc(nodeinfo.NodeInfoPath, handler.LogHandlerFunc(http.HandlerFunc(ni.NodeInfoDiscover)))
  32. write.HandleFunc(niCfg.InfoURL, handler.LogHandlerFunc(http.HandlerFunc(ni.NodeInfo)))
  33. }