35 lines
723 B
Go
35 lines
723 B
Go
|
package baas
|
||
|
|
||
|
import (
|
||
|
"github.com/labstack/echo/v4"
|
||
|
"github.com/labstack/echo/v4/middleware"
|
||
|
)
|
||
|
|
||
|
type Server struct {
|
||
|
*echo.Echo
|
||
|
}
|
||
|
|
||
|
func NewServer() *Server {
|
||
|
e := echo.New()
|
||
|
|
||
|
e.Static("/", "public")
|
||
|
|
||
|
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{
|
||
|
// TODO: add CORS origins
|
||
|
AllowOrigins: []string{},
|
||
|
AllowCredentials: true,
|
||
|
AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept},
|
||
|
}))
|
||
|
|
||
|
// TODO: attach error handler
|
||
|
// e.HTTPErrorHandler = ...
|
||
|
|
||
|
s := &Server{e}
|
||
|
|
||
|
return s
|
||
|
}
|