Skip to content

Commit

Permalink
Merge pull request #37 from buildbarn/inline-portal-service
Browse files Browse the repository at this point in the history
Inline cmd/bb_portal/portal-service.go
  • Loading branch information
mortenmj authored Oct 16, 2024
2 parents 8a037e0 + 8ecc484 commit d149a39
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 38 deletions.
5 changes: 1 addition & 4 deletions cmd/bb_portal/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
26 changes: 26 additions & 0 deletions cmd/bb_portal/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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)
}
34 changes: 0 additions & 34 deletions cmd/bb_portal/portal_service.go

This file was deleted.

0 comments on commit d149a39

Please sign in to comment.