aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/cmd_serve.go
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-11-02 00:00:35 +0900
committernsfisis <nsfisis@gmail.com>2025-11-02 00:00:35 +0900
commit104341ddc4add57f83c58cb3fabb23b6fbfdd3e4 (patch)
tree862b109fe257e6170a88929729dae3bddfb6eb49 /backend/cmd_serve.go
parentba1e0c904f810193f25d4f88cc2bb168f1d625fe (diff)
downloadfeedaka-104341ddc4add57f83c58cb3fabb23b6fbfdd3e4.tar.gz
feedaka-104341ddc4add57f83c58cb3fabb23b6fbfdd3e4.tar.zst
feedaka-104341ddc4add57f83c58cb3fabb23b6fbfdd3e4.zip
Diffstat (limited to 'backend/cmd_serve.go')
-rw-r--r--backend/cmd_serve.go33
1 files changed, 29 insertions, 4 deletions
diff --git a/backend/cmd_serve.go b/backend/cmd_serve.go
index 66ceaf9..33de515 100644
--- a/backend/cmd_serve.go
+++ b/backend/cmd_serve.go
@@ -17,11 +17,13 @@ import (
"github.com/99designs/gqlgen/graphql/handler/lru"
"github.com/99designs/gqlgen/graphql/handler/transport"
"github.com/hashicorp/go-multierror"
+ "github.com/labstack/echo-contrib/session"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/mmcdole/gofeed"
"github.com/vektah/gqlparser/v2/ast"
+ "undef.ninja/x/feedaka/auth"
"undef.ninja/x/feedaka/db"
"undef.ninja/x/feedaka/graphql"
"undef.ninja/x/feedaka/graphql/resolver"
@@ -149,11 +151,16 @@ func runServe(database *sql.DB) {
queries := db.New(database)
+ // Initialize session config
+ sessionConfig := auth.NewSessionConfig()
+
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.Use(middleware.CORS())
+ // Setup session middleware
+ e.Use(session.Middleware(sessionConfig.GetStore()))
e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
HTML5: true,
@@ -162,7 +169,11 @@ func runServe(database *sql.DB) {
}))
// Setup GraphQL server
- srv := handler.New(graphql.NewExecutableSchema(graphql.Config{Resolvers: &resolver.Resolver{DB: database, Queries: queries}}))
+ srv := handler.New(graphql.NewExecutableSchema(graphql.Config{Resolvers: &resolver.Resolver{
+ DB: database,
+ Queries: queries,
+ SessionConfig: sessionConfig,
+ }}))
srv.AddTransport(transport.Options{})
srv.AddTransport(transport.GET{})
@@ -175,9 +186,23 @@ func runServe(database *sql.DB) {
Cache: lru.New[string](100),
})
- // GraphQL endpoints
- e.POST("/graphql", echo.WrapHandler(srv))
- e.GET("/graphql", echo.WrapHandler(srv))
+ // GraphQL endpoints with authentication middleware
+ graphqlGroup := e.Group("/graphql")
+ graphqlGroup.Use(SessionAuthMiddleware(sessionConfig))
+ graphqlGroup.POST("", func(c echo.Context) error {
+ // Add Echo context to GraphQL context
+ ctx := context.WithValue(c.Request().Context(), "echo", c)
+ req := c.Request().WithContext(ctx)
+ srv.ServeHTTP(c.Response(), req)
+ return nil
+ })
+ graphqlGroup.GET("", func(c echo.Context) error {
+ // Add Echo context to GraphQL context
+ ctx := context.WithValue(c.Request().Context(), "echo", c)
+ req := c.Request().WithContext(ctx)
+ srv.ServeHTTP(c.Response(), req)
+ return nil
+ })
ctx, cancel := context.WithCancel(context.Background())
defer cancel()