2023-06-01 16:34:41 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-07-12 13:30:25 +00:00
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
2023-07-03 09:38:34 +00:00
|
|
|
"cliffbreak.de/hgoe-sas-server/pkg/middlewares"
|
2023-06-05 16:05:25 +00:00
|
|
|
"cliffbreak.de/hgoe-sas-server/pkg/utils"
|
2023-07-12 13:30:25 +00:00
|
|
|
|
|
|
|
"github.com/labstack/echo/v5"
|
2023-06-01 16:34:41 +00:00
|
|
|
"github.com/pocketbase/pocketbase"
|
2023-07-12 13:30:25 +00:00
|
|
|
"github.com/pocketbase/pocketbase/core"
|
2023-06-01 16:34:41 +00:00
|
|
|
"github.com/pterm/pterm"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
pterm.Info.Println("Loading environment variables...")
|
|
|
|
utils.LoadEnv()
|
|
|
|
pterm.Info.Println("Starting PocketBase server...")
|
|
|
|
app := pocketbase.New()
|
|
|
|
|
2023-07-03 09:38:34 +00:00
|
|
|
app.OnBeforeServe().Add(middlewares.ServeSPA(utils.GetEnv("WEBAPP", "./webapp")))
|
|
|
|
|
2023-07-12 13:30:25 +00:00
|
|
|
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
|
|
|
|
})
|
|
|
|
|
2023-06-01 16:34:41 +00:00
|
|
|
if err := app.Start(); err != nil {
|
|
|
|
pterm.Fatal.Println(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|