2024-03-12 15:49:08 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log/slog"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
2024-03-18 21:54:35 +01:00
|
|
|
"github.com/labstack/echo-contrib/session"
|
2024-03-12 15:49:08 +01:00
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
"github.com/labstack/echo/v4/middleware"
|
2024-03-18 21:54:35 +01:00
|
|
|
"github.com/quasoft/memstore"
|
2024-03-12 15:49:08 +01:00
|
|
|
"github.com/r3labs/sse/v2"
|
|
|
|
"gitlab.unjx.de/flohoss/godash/handlers"
|
|
|
|
"gitlab.unjx.de/flohoss/godash/internal/env"
|
|
|
|
"gitlab.unjx.de/flohoss/godash/services"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
env, err := env.Parse()
|
|
|
|
if err != nil {
|
|
|
|
slog.Error("cannot parse environment variables", "err", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
e := echo.New()
|
|
|
|
e.HideBanner = true
|
|
|
|
e.HidePort = true
|
|
|
|
|
|
|
|
e.Pre(middleware.RemoveTrailingSlash())
|
|
|
|
e.Use(middleware.Recover())
|
|
|
|
e.Use(middleware.GzipWithConfig(middleware.GzipConfig{
|
|
|
|
Skipper: func(c echo.Context) bool {
|
2024-03-18 21:54:35 +01:00
|
|
|
return strings.Contains(c.Path(), "sse") || strings.Contains(c.Path(), "sign")
|
2024-03-12 15:49:08 +01:00
|
|
|
},
|
|
|
|
}))
|
2024-03-18 21:54:35 +01:00
|
|
|
e.Use(session.Middleware(memstore.NewMemStore([]byte(env.SessionKey))))
|
2024-03-12 15:49:08 +01:00
|
|
|
|
|
|
|
sse := sse.New()
|
|
|
|
sse.AutoReplay = false
|
|
|
|
|
|
|
|
s := services.NewSystemService(sse)
|
2024-03-15 18:56:32 +01:00
|
|
|
w := services.NewWeatherService(sse, env)
|
2024-03-12 15:49:08 +01:00
|
|
|
b := services.NewBookmarkService()
|
|
|
|
|
2024-03-18 21:54:35 +01:00
|
|
|
appHandler := handlers.NewAppHandler(env, s, w, b)
|
|
|
|
authHandler := handlers.NewAuthHandler(env)
|
|
|
|
handlers.SetupRoutes(e, sse, appHandler, authHandler)
|
2024-03-12 15:49:08 +01:00
|
|
|
|
2024-03-18 21:54:35 +01:00
|
|
|
slog.Info("starting server", "url", env.PublicUrl)
|
2024-03-12 15:49:08 +01:00
|
|
|
if err := e.Start(fmt.Sprintf(":%d", env.Port)); err != http.ErrServerClosed {
|
|
|
|
slog.Error("cannot start server", "err", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|