From 8ecc484eae0b10c611469e51ef94f3fcd47de93a Mon Sep 17 00:00:00 2001 From: Morten Mjelva Date: Wed, 16 Oct 2024 16:51:03 +0200 Subject: [PATCH] Inline cmd/bb_portal/portal-service.go --- cmd/bb_portal/BUILD.bazel | 5 +---- cmd/bb_portal/main.go | 26 +++++++++++++++++++++++++ cmd/bb_portal/portal_service.go | 34 --------------------------------- 3 files changed, 27 insertions(+), 38 deletions(-) delete mode 100644 cmd/bb_portal/portal_service.go diff --git a/cmd/bb_portal/BUILD.bazel b/cmd/bb_portal/BUILD.bazel index 1dc7e90..8346efd 100644 --- a/cmd/bb_portal/BUILD.bazel +++ b/cmd/bb_portal/BUILD.bazel @@ -4,10 +4,7 @@ load("@rules_oci//oci:defs.bzl", "oci_image", "oci_image_index") go_library( name = "bb_portal_lib", - srcs = [ - "main.go", - "portal_service.go", - ], + srcs = ["main.go"], importpath = "github.com/buildbarn/bb-portal/cmd/bb_portal", visibility = ["//visibility:private"], deps = [ diff --git a/cmd/bb_portal/main.go b/cmd/bb_portal/main.go index 21234e9..9fbc696 100644 --- a/cmd/bb_portal/main.go +++ b/cmd/bb_portal/main.go @@ -4,9 +4,15 @@ import ( "context" "flag" "log/slog" + "net/http" + "net/http/httputil" + "net/url" "os" "time" + "entgo.io/contrib/entgql" + "github.com/99designs/gqlgen/graphql/handler" + "github.com/99designs/gqlgen/graphql/playground" "github.com/fsnotify/fsnotify" "github.com/gorilla/mux" _ "github.com/mattn/go-sqlite3" @@ -15,7 +21,9 @@ import ( "github.com/buildbarn/bb-portal/ent/gen/ent" "github.com/buildbarn/bb-portal/ent/gen/ent/migrate" + "github.com/buildbarn/bb-portal/internal/api" "github.com/buildbarn/bb-portal/internal/api/grpc/bes" + "github.com/buildbarn/bb-portal/internal/graphql" "github.com/buildbarn/bb-portal/pkg/processing" "github.com/buildbarn/bb-portal/pkg/proto/configuration/bb_portal" "github.com/buildbarn/bb-storage/pkg/global" @@ -154,3 +162,21 @@ func fatal(msg string, args ...any) { slog.Error(msg, args...) os.Exit(1) } + +func newPortalService(archiver processing.BlobMultiArchiver, dbClient *ent.Client, router *mux.Router) { + srv := handler.NewDefaultServer(graphql.NewSchema(dbClient)) + srv.Use(entgql.Transactioner{TxOpener: dbClient}) + + router.PathPrefix("/graphql").Handler(srv) + router.Handle("/graphiql", playground.Handler("GraphQL Playground", "/graphql")) + router.Handle("/api/v1/bep/upload", api.NewBEPUploadHandler(dbClient, archiver)).Methods("POST") + router.PathPrefix("/").Handler(frontendServer()) +} + +func frontendServer() http.Handler { + targetURL := &url.URL{ + Scheme: "http", + Host: "localhost:3000", + } + return httputil.NewSingleHostReverseProxy(targetURL) +} diff --git a/cmd/bb_portal/portal_service.go b/cmd/bb_portal/portal_service.go deleted file mode 100644 index 80afc9b..0000000 --- a/cmd/bb_portal/portal_service.go +++ /dev/null @@ -1,34 +0,0 @@ -package main - -import ( - "net/http" - "net/http/httputil" - "net/url" - - "entgo.io/contrib/entgql" - "github.com/99designs/gqlgen/graphql/handler" - "github.com/99designs/gqlgen/graphql/playground" - "github.com/buildbarn/bb-portal/ent/gen/ent" - "github.com/buildbarn/bb-portal/internal/api" - "github.com/buildbarn/bb-portal/internal/graphql" - "github.com/buildbarn/bb-portal/pkg/processing" - "github.com/gorilla/mux" -) - -func newPortalService(archiver processing.BlobMultiArchiver, dbClient *ent.Client, router *mux.Router) { - srv := handler.NewDefaultServer(graphql.NewSchema(dbClient)) - srv.Use(entgql.Transactioner{TxOpener: dbClient}) - - router.PathPrefix("/graphql").Handler(srv) - router.Handle("/graphiql", playground.Handler("GraphQL Playground", "/graphql")) - router.Handle("/api/v1/bep/upload", api.NewBEPUploadHandler(dbClient, archiver)).Methods("POST") - router.PathPrefix("/").Handler(frontendServer()) -} - -func frontendServer() http.Handler { - targetURL := &url.URL{ - Scheme: "http", - Host: "localhost:3000", - } - return httputil.NewSingleHostReverseProxy(targetURL) -}