diff --git a/Dockerfile b/Dockerfile index 8b4402b..697c4e0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,7 +33,7 @@ COPY Makefile ./ # Build the frontend COPY frontend frontend -RUN VITE_API_URL=/api npm run --prefix frontend build +RUN VITE_API_URL=/api VITE_OIDC_URL=/oidc npm run --prefix frontend build # Build backend COPY goshort.go ./ diff --git a/Makefile b/Makefile index b503c4e..c7f940b 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ install-backend: install: install-frontend install-backend frontend: - VITE_API_URL=/api npm run --prefix frontend build + VITE_API_URL=/api VITE_OIDC_URL=/oidc npm run --prefix frontend build VERSION=$(shell git describe --tags --abbrev=0) @@ -25,10 +25,10 @@ dev: go run goshort.go dev lint-frontend: - VITE_API_URL=/api npm run --prefix frontend lint + VITE_API_URL=/api VITE_OIDC_URL=/oidc npm run --prefix frontend lint lint-frontend-fix: - VITE_API_URL=/api npm run --prefix frontend lint:fix + VITE_API_URL=/api VITE_OIDC_URL=/oidc npm run --prefix frontend lint:fix lint-backend: golangci-lint run diff --git a/cmd/dev/dev.go b/cmd/dev/dev.go index f316643..fd54009 100644 --- a/cmd/dev/dev.go +++ b/cmd/dev/dev.go @@ -19,6 +19,7 @@ import ( oidcserver "git.maronato.dev/maronato/goshort/internal/server/oidc" shortserver "git.maronato.dev/maronato/goshort/internal/server/short" staticssterver "git.maronato.dev/maronato/goshort/internal/server/static" + configservice "git.maronato.dev/maronato/goshort/internal/service/config" oidcservice "git.maronato.dev/maronato/goshort/internal/service/oidc" shortservice "git.maronato.dev/maronato/goshort/internal/service/short" shortlogservice "git.maronato.dev/maronato/goshort/internal/service/shortlog" @@ -105,17 +106,18 @@ func serveAPI(ctx context.Context, cfg *config.Config) error { tokenService := tokenservice.NewTokenService(storage) shortLogService := shortlogservice.NewShortLogService(storage) oidcService := oidcservice.NewOIDCService(ctx, cfg) + configService := configservice.NewConfigService(cfg) // Start short log worker stopWorker, _ := shortLogService.StartWorker(ctx) defer stopWorker() // Create handlers - apiHandler := apiserver.NewAPIHandler(shortService, userService, tokenService, shortLogService) + apiHandler := apiserver.NewAPIHandler(shortService, userService, tokenService, shortLogService, configService) shortHandler := shortserver.NewShortHandler(shortService, shortLogService) healthcheckHandler := healthcheckserver.NewHealthcheckHandler(storage) docsHandler := staticssterver.NewStaticHandler(cfg, "/api/docs", docs.Assets()) - oidcHandler := oidcserver.NewOIDCHandler(oidcService, userService) + oidcHandler := oidcserver.NewOIDCHandler(cfg, oidcService, userService) // Create routers apiRouter := apiserver.NewAPIRouter(apiHandler) @@ -146,6 +148,7 @@ func serveAPI(ctx context.Context, cfg *config.Config) error { if oidcService != nil { srv.Mux.Mount("/oidc", oidcRouter) } + srv.Mux.Mount("/healthz", healthcheckRouter) srv.Mux.Mount("/", chainedRouter) diff --git a/cmd/serve/serve.go b/cmd/serve/serve.go index 3c38f6e..a32ab45 100644 --- a/cmd/serve/serve.go +++ b/cmd/serve/serve.go @@ -17,6 +17,7 @@ import ( oidcserver "git.maronato.dev/maronato/goshort/internal/server/oidc" shortserver "git.maronato.dev/maronato/goshort/internal/server/short" staticssterver "git.maronato.dev/maronato/goshort/internal/server/static" + configservice "git.maronato.dev/maronato/goshort/internal/service/config" oidcservice "git.maronato.dev/maronato/goshort/internal/service/oidc" shortservice "git.maronato.dev/maronato/goshort/internal/service/short" shortlogservice "git.maronato.dev/maronato/goshort/internal/service/shortlog" @@ -78,18 +79,19 @@ func exec(ctx context.Context, cfg *config.Config) error { tokenService := tokenservice.NewTokenService(storage) shortLogService := shortlogservice.NewShortLogService(storage) oidcService := oidcservice.NewOIDCService(ctx, cfg) + configService := configservice.NewConfigService(cfg) // Start short log worker stopWorker, _ := shortLogService.StartWorker(ctx) defer stopWorker() // Create handlers - apiHandler := apiserver.NewAPIHandler(shortService, userService, tokenService, shortLogService) + apiHandler := apiserver.NewAPIHandler(shortService, userService, tokenService, shortLogService, configService) shortHandler := shortserver.NewShortHandler(shortService, shortLogService) staticHandler := staticssterver.NewStaticHandler(cfg, "/", frontend.Assets()) healthcheckHandler := healthcheckserver.NewHealthcheckHandler(storage) docsHandler := staticssterver.NewStaticHandler(cfg, "/api/docs", docs.Assets()) - oidcHandler := oidcserver.NewOIDCHandler(oidcService, userService) + oidcHandler := oidcserver.NewOIDCHandler(cfg, oidcService, userService) // Create routers apiRouter := apiserver.NewAPIRouter(apiHandler) diff --git a/cmd/shared/shared.go b/cmd/shared/shared.go index 0cf05e8..3f24fed 100644 --- a/cmd/shared/shared.go +++ b/cmd/shared/shared.go @@ -71,6 +71,7 @@ func RegisterServerFlags(fs *flag.FlagSet, cfg *config.Config) { fs.StringVar(&cfg.OIDCClientID, "oidc-client-id", "", "OIDC client ID") fs.StringVar(&cfg.OIDCClientSecret, "oidc-client-secret", "", "OIDC client secret") fs.StringVar(&cfg.OIDCRedirectURL, "oidc-redirect-url", "", "OIDC redirect URL") + fs.StringVar(&cfg.OIDCIssuerName, "oidc-issuer-name", config.DefaultOIDCIssuerName, "OIDC issuer name") } // InitStorage initializes the storage depending on the config. diff --git a/frontend/src/components/UserForm.tsx b/frontend/src/components/UserForm.tsx index e2b1c42..a1e324b 100644 --- a/frontend/src/components/UserForm.tsx +++ b/frontend/src/components/UserForm.tsx @@ -8,6 +8,8 @@ import { useSearchParams, } from "react-router-dom" +import { useServerConfig } from "../hooks/useServerConfig" + import Button from "./Button" const actionOptions = { @@ -102,6 +104,7 @@ const UserForm: FunctionComponent<{ }> = ({ action }) => { const [params] = useSearchParams() const from = params.get("from") || "/" + const serverConfig = useServerConfig() const opts = actionOptions[action] @@ -128,89 +131,99 @@ const UserForm: FunctionComponent<{ const passwordScore = useMemo(() => passwordOMeter(password), [password]) return ( -