From 36d9861517e3133b8db261793733102e648b72f1 Mon Sep 17 00:00:00 2001 From: Lakhan Samani Date: Mon, 31 Jan 2022 14:30:13 +0530 Subject: [PATCH] Fix getting host --- Dockerfile | 2 ++ app/src/Root.tsx | 2 ++ server/handlers/app.go | 4 +--- server/utils/urls.go | 11 ++++++----- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index d0045c4..ebc1aea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,7 +24,9 @@ FROM alpine:latest WORKDIR /root/ RUN mkdir app dashboard COPY --from=node-builder /authorizer/app/build app/build +COPY --from=node-builder /authorizer/app/favicon_io app/favicon_io COPY --from=node-builder /authorizer/dashboard/build dashboard/build +COPY --from=node-builder /authorizer/dashboard/favicon_io dashboard/favicon_io COPY --from=go-builder /authorizer/build build COPY templates templates EXPOSE 8080 diff --git a/app/src/Root.tsx b/app/src/Root.tsx index d4f98f6..f5ba765 100644 --- a/app/src/Root.tsx +++ b/app/src/Root.tsx @@ -9,9 +9,11 @@ const Dashboard = lazy(() => import('./pages/dashboard')); export default function Root() { const { token, loading, config } = useAuthorizer(); + console.log(config); useEffect(() => { if (token) { const url = new URL(config.redirectURL || '/app'); + console.log('=> url', url); if (url.origin !== window.location.origin) { window.location.href = config.redirectURL || '/app'; } diff --git a/server/handlers/app.go b/server/handlers/app.go index ef893ff..563e502 100644 --- a/server/handlers/app.go +++ b/server/handlers/app.go @@ -33,10 +33,8 @@ func AppHandler() gin.HandlerFunc { var stateObj State if state == "" { - stateObj.AuthorizerURL = hostname - stateObj.RedirectURL = stateObj.AuthorizerURL + "/app" - + stateObj.RedirectURL = hostname + "/app" } else { decodedState, err := utils.DecryptB64(state) if err != nil { diff --git a/server/utils/urls.go b/server/utils/urls.go index 284e259..f95fc70 100644 --- a/server/utils/urls.go +++ b/server/utils/urls.go @@ -10,12 +10,13 @@ import ( // GetHost returns hostname from request context func GetHost(c *gin.Context) string { - scheme := "http" - if c.Request.TLS != nil { - scheme = "https" + scheme := c.Request.Header.Get("X-Forwarded-Proto") + if scheme != "https" { + scheme = "http" } - log.Println("=> url:", scheme+"://"+c.Request.Host) - return scheme + "://" + c.Request.Host + host := c.Request.Host + log.Println("=> host:", scheme+"://"+host) + return scheme + "://" + host } // GetHostName function returns hostname and port