delphi.market/server/server.go

43 lines
906 B
Go
Raw Normal View History

package server
import (
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"git.ekzyis.com/ekzyis/delphi.market/server/router"
)
type Server struct {
*echo.Echo
}
2024-07-09 20:41:29 +00:00
type Context = router.Context
2024-07-09 20:41:29 +00:00
func New(ctx Context) *Server {
var (
e *echo.Echo
s *Server
)
e = echo.New()
2024-07-09 20:41:29 +00:00
e.Static("/", "public")
2024-07-09 20:41:29 +00:00
e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
Format: "${time_custom} ${method} ${uri} ${status}\n",
CustomTimeFormat: "2006-01-02 15:04:05.00000-0700",
}))
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"http://localhost:4224", "https://delphi.market", "https://dev1.delphi.market"},
AllowCredentials: true,
AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept},
}))
2024-07-09 20:41:29 +00:00
2024-07-10 06:20:04 +00:00
e.HTTPErrorHandler = httpErrorHandler(ctx)
s = &Server{e}
2024-07-09 20:41:29 +00:00
router.Init(e, ctx)
return s
}