A clean, Markdown-based publishing platform made for writers. Write together, and build a community. https://writefreely.org
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 

58 rindas
2.0 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. hostSubroute := cfg.App.Host[strings.Index(cfg.App.Host, "://")+3:]
  12. if cfg.App.SingleUser {
  13. hostSubroute = "{domain}"
  14. } else {
  15. if strings.HasPrefix(hostSubroute, "localhost") {
  16. hostSubroute = "localhost"
  17. }
  18. }
  19. if cfg.App.SingleUser {
  20. log.Info("Adding %s routes (single user)...", hostSubroute)
  21. } else {
  22. log.Info("Adding %s routes (multi-user)...", hostSubroute)
  23. }
  24. // Primary app routes
  25. write := r.Host(hostSubroute).Subrouter()
  26. // Federation endpoints
  27. // nodeinfo
  28. niCfg := nodeInfoConfig(cfg)
  29. ni := nodeinfo.NewService(*niCfg, nodeInfoResolver{cfg, db})
  30. write.HandleFunc(nodeinfo.NodeInfoPath, handler.LogHandlerFunc(http.HandlerFunc(ni.NodeInfoDiscover)))
  31. write.HandleFunc(niCfg.InfoURL, handler.LogHandlerFunc(http.HandlerFunc(ni.NodeInfo)))
  32. // Handle posts
  33. write.HandleFunc("/api/posts", handler.All(newPost)).Methods("POST")
  34. posts := write.PathPrefix("/api/posts/").Subrouter()
  35. posts.HandleFunc("/{post:[a-zA-Z0-9]{10}}", handler.All(fetchPost)).Methods("GET")
  36. posts.HandleFunc("/{post:[a-zA-Z0-9]{10}}", handler.All(existingPost)).Methods("POST", "PUT")
  37. posts.HandleFunc("/{post:[a-zA-Z0-9]{10}}", handler.All(deletePost)).Methods("DELETE")
  38. posts.HandleFunc("/{post:[a-zA-Z0-9]{10}}/{property}", handler.All(fetchPostProperty)).Methods("GET")
  39. posts.HandleFunc("/claim", handler.All(addPost)).Methods("POST")
  40. posts.HandleFunc("/disperse", handler.All(dispersePost)).Methods("POST")
  41. // All the existing stuff
  42. write.HandleFunc("/{action}/edit", handler.Web(handleViewPad, UserLevelOptional)).Methods("GET")
  43. write.HandleFunc("/{action}/meta", handler.Web(handleViewMeta, UserLevelOptional)).Methods("GET")
  44. // Collections
  45. if cfg.App.SingleUser {
  46. } else {
  47. // Posts
  48. write.HandleFunc("/{post}", handler.Web(handleViewPost, UserLevelOptional))
  49. }
  50. }