magicwallet/server/server.go
ekzyis 92876c5011 users, sessions and wallets w/o authentication
* if a request has no session cookie, a new user, session and wallet is created and session cookie is set
* if a request has a session cookie and session exists in db, we will fetch user and wallet from db
* this means that we have a user and wallet during each render without any login required
2024-12-15 21:56:26 +01:00

41 lines
899 B
Go

package server
import (
"github.com/ekzyis/magicwallet/server/router"
"github.com/ekzyis/magicwallet/server/router/context"
"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 {
e := echo.New()
e.Static("/", "public")
e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
Format: "${time_custom} ${remote_ip} ${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 = ...
router.Handle(e, hc)
s := &Server{e}
return s
}