1
0

routers.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package router
  2. import (
  3. "github.com/0xJacky/Nginx-UI/api/analytic"
  4. "github.com/0xJacky/Nginx-UI/api/certificate"
  5. "github.com/0xJacky/Nginx-UI/api/cluster"
  6. "github.com/0xJacky/Nginx-UI/api/config"
  7. "github.com/0xJacky/Nginx-UI/api/nginx"
  8. "github.com/0xJacky/Nginx-UI/api/notification"
  9. "github.com/0xJacky/Nginx-UI/api/openai"
  10. "github.com/0xJacky/Nginx-UI/api/sites"
  11. "github.com/0xJacky/Nginx-UI/api/streams"
  12. "github.com/0xJacky/Nginx-UI/api/system"
  13. "github.com/0xJacky/Nginx-UI/api/template"
  14. "github.com/0xJacky/Nginx-UI/api/terminal"
  15. "github.com/0xJacky/Nginx-UI/api/upstream"
  16. "github.com/0xJacky/Nginx-UI/api/user"
  17. "github.com/gin-contrib/static"
  18. "github.com/gin-gonic/gin"
  19. "net/http"
  20. )
  21. func InitRouter() *gin.Engine {
  22. r := gin.New()
  23. r.Use(gin.Logger())
  24. r.Use(recovery())
  25. r.Use(cacheJs())
  26. //r.Use(OperationSync())
  27. r.Use(static.Serve("/", mustFS("")))
  28. r.NoRoute(func(c *gin.Context) {
  29. c.JSON(http.StatusNotFound, gin.H{
  30. "message": "not found",
  31. })
  32. })
  33. root := r.Group("/api")
  34. {
  35. system.InitPublicRouter(root)
  36. user.InitAuthRouter(root)
  37. // Authorization required not websocket request
  38. g := root.Group("/", authRequired(), proxy())
  39. {
  40. analytic.InitRouter(g)
  41. user.InitManageUserRouter(g)
  42. nginx.InitRouter(g)
  43. sites.InitRouter(g)
  44. streams.InitRouter(g)
  45. config.InitRouter(g)
  46. template.InitRouter(g)
  47. certificate.InitCertificateRouter(g)
  48. certificate.InitDNSCredentialRouter(g)
  49. system.InitPrivateRouter(g)
  50. openai.InitRouter(g)
  51. cluster.InitRouter(g)
  52. notification.InitRouter(g)
  53. }
  54. // Authorization required and websocket request
  55. w := root.Group("/", authRequired(), proxyWs())
  56. {
  57. analytic.InitWebSocketRouter(w)
  58. certificate.InitCertificateWebSocketRouter(w)
  59. terminal.InitRouter(w)
  60. nginx.InitNginxLogRouter(w)
  61. upstream.InitRouter(w)
  62. }
  63. }
  64. return r
  65. }