magicwallet/server/server.go

41 lines
899 B
Go
Raw Normal View History

package server
2024-10-24 14:11:06 +02:00
import (
2024-12-11 08:18:43 +01:00
"github.com/ekzyis/magicwallet/server/router"
"github.com/ekzyis/magicwallet/server/router/context"
2024-10-24 14:11:06 +02:00
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
type Server struct {
*echo.Echo
}
type Context = context.Context
func New(hc Context) *Server {
2024-10-24 14:11:06 +02:00
e := echo.New()
e.Static("/", "public")
e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
Format: "${time_custom} ${remote_ip} ${method} ${uri} ${status}\n",
2024-10-24 14:11:06 +02:00
CustomTimeFormat: "2006-01-02 15:04:05.00000-0700",
}))
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
// TODO: add CORS origins
AllowOrigins: []string{},
AllowCredentials: true,
AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept},
}))
// TODO: attach error handler
// e.HTTPErrorHandler = ...
router.Handle(e, hc)
2024-10-24 14:11:06 +02:00
s := &Server{e}
return s
}