From cc1efd5d85d3180328969d40942399a7bf315162 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 16 Mar 2024 17:13:29 -0400 Subject: [PATCH] feat: add dashboard as a submodule and register embed and routing in account api --- .gitmodules | 3 +++ api/account/account.go | 13 +++++++++++++ api/account/app | 1 + 3 files changed, 17 insertions(+) create mode 100644 .gitmodules create mode 160000 api/account/app diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..7e7e0a6 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "api/account/app"] + path = api/account/app + url = https://git.lumeweb.com/LumeWeb/portal-dashboard.git diff --git a/api/account/account.go b/api/account/account.go index 68788e4..f667976 100644 --- a/api/account/account.go +++ b/api/account/account.go @@ -3,7 +3,9 @@ package account import ( "context" "crypto/ed25519" + "embed" _ "embed" + "io/fs" "net/http" "time" @@ -27,6 +29,9 @@ import ( //go:embed swagger.yaml var swagSpec []byte +//go:embed app/build/client/build +var appFs embed.FS + var ( _ registry.API = (*AccountAPI)(nil) _ router.RoutableAPI = (*AccountAPI)(nil) @@ -328,6 +333,13 @@ func (a AccountAPI) Routes() (*httprouter.Router, error) { Purpose: account.JWTPurposeLogin, }) + appFiles, _ := fs.Sub(appFs, "app") + appServ := http.FileServer(http.FS(appFiles)) + + appHandler := func(c jape.Context) { + appServ.ServeHTTP(c.ResponseWriter, c.Request) + } + routes := map[string]jape.Handler{ "POST /api/auth/ping": middleware.ApplyMiddlewares(a.ping, pingAuthMw, middleware.ProxyMiddleware), "POST /api/auth/login": middleware.ApplyMiddlewares(a.login, loginAuthMw2fa, middleware.ProxyMiddleware), @@ -340,6 +352,7 @@ func (a AccountAPI) Routes() (*httprouter.Router, error) { "POST /api/auth/password-reset/request": middleware.ApplyMiddlewares(a.passwordResetRequest, middleware.ProxyMiddleware), "POST /api/auth/password-reset/confirm": middleware.ApplyMiddlewares(a.passwordResetConfirm, middleware.ProxyMiddleware), "GET /api/account": middleware.ApplyMiddlewares(a.accountInfo, authMw, middleware.ProxyMiddleware), + "GET /*path": middleware.ApplyMiddlewares(appHandler, middleware.ProxyMiddleware), } routes, err := swagger.Swagger(swagSpec, routes) diff --git a/api/account/app b/api/account/app new file mode 160000 index 0000000..7d25a7a --- /dev/null +++ b/api/account/app @@ -0,0 +1 @@ +Subproject commit 7d25a7a63e7b196ff903c7b9202d975aef1a98e1