init.go 632 B

123456789101112131415161718192021222324252627282930
  1. package server
  2. import (
  3. "net/http"
  4. "github.com/labstack/echo/v4"
  5. "github.com/labstack/echo/v4/middleware"
  6. )
  7. func NewServer(s Server) *echo.Echo {
  8. e := echo.New()
  9. e.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
  10. return func(c echo.Context) error {
  11. if err := next(c); err != nil {
  12. return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
  13. }
  14. return nil
  15. }
  16. })
  17. e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
  18. Root: "frontend/build",
  19. HTML5: true,
  20. }))
  21. e.GET("/api", s.watchUpdates)
  22. e.POST("/api/:type", s.create)
  23. e.DELETE("/api/:type/:namespace/:name", s.delete)
  24. return e
  25. }