1
0
Fork 0
forked from Kispi/Core
HGOE-SaS/server/main.go

41 lines
874 B
Go
Raw Permalink Normal View History

package main
import (
"net/http"
"time"
"cliffbreak.de/hgoe-sas-server/pkg/middlewares"
2023-06-05 16:05:25 +00:00
"cliffbreak.de/hgoe-sas-server/pkg/utils"
"github.com/labstack/echo/v5"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/core"
"github.com/pterm/pterm"
)
func main() {
pterm.Info.Println("Loading environment variables...")
utils.LoadEnv()
pterm.Info.Println("Starting PocketBase server...")
app := pocketbase.New()
app.OnBeforeServe().Add(middlewares.ServeSPA(utils.GetEnv("WEBAPP", "./webapp")))
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
e.Router.AddRoute(echo.Route{
Method: http.MethodGet,
Path: "/api/time",
Handler: func(c echo.Context) error {
return c.String(http.StatusOK, time.Now().Format(time.RFC3339))
},
})
return nil
})
if err := app.Start(); err != nil {
pterm.Fatal.Println(err)
}
}