Skip to content

Commit e93df1a

Browse files
taymoor89ArtieReus
andauthored
chore(greenhouse): add org to subdomain in non-dev environments (#1259)
* chore(greenhouse): add org to subdomain in non-dev environments Co-authored-by: Arturo <a.reuschenbach.puncernau@sap.com> * refactor(greenhouse): use generic way to detect environment --------- Co-authored-by: Arturo <a.reuschenbach.puncernau@sap.com>
1 parent 8ea0089 commit e93df1a

4 files changed

Lines changed: 33 additions & 20 deletions

File tree

.changeset/ready-trees-chew.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudoperators/juno-app-greenhouse": patch
3+
---
4+
5+
For non-development environment always put organization name as subdomain.

.github/scripts/build-vite-app.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package_name=$(jq -r '.name' $PACKAGE_PATH/package.json)
88
app_props_url=$PREVIEW_URL/$TARGET_FOLDER/appProps.json
99

1010
# Run build using turbo
11-
VITE_APP_PROPS_URL=$app_props_url pnpx turbo run build:static --filter $package_name -- --base ./
11+
NODE_ENV=$NODE_ENV VITE_APP_PROPS_URL=$app_props_url pnpx turbo run build:static --filter $package_name -- --base ./
1212

1313
# Copy build folder to deploy path
1414
mkdir -p "$DEPLOY_PATH/$TARGET_FOLDER"

.github/workflows/deploy-pr-preview.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ jobs:
151151
TARGET_FOLDER: greenhouse
152152
APP_PROPS_BASE64: ${{ secrets.GREENHOUSE_APP_PROPS_BASE64 }}
153153
PREVIEW_URL: ${{ env.PREVIEW_URL }}
154+
NODE_ENV: development
154155
continue-on-error: true
155156

156157
- name: Build EXAMPLE if changes detected

apps/greenhouse/src/components/AuthProvider.tsx

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,33 @@ import React, { createContext, useContext, useState, useMemo, useRef, useEffect
77
import { oidcSession, mockedSession, tokenSession } from "@cloudoperators/juno-oauth"
88

99
const setOrganizationToUrl = (groups: any, enableHashedRouting: boolean) => {
10-
const orgString = groups?.find((g: any) => g.indexOf("organization:") === 0)
11-
if (orgString) {
12-
const name = orgString.split(":")[1]
13-
let url = new URL(window.location.href)
14-
15-
// Check if the organization name is already in the URL path or hash then don't change it
16-
const currentPath = enableHashedRouting ? url.hash.replace("#/", "") : url.pathname
17-
const currentFirstSegment = currentPath.split("/").filter(Boolean)[0]
18-
if (name === currentFirstSegment) return
19-
20-
// if enableHashedRouting is true, set the hash, otherwise set the pathname
21-
const pathWithOrg = `/${name}`
22-
if (enableHashedRouting) {
23-
url.hash = pathWithOrg
24-
} else {
25-
url.pathname = pathWithOrg
26-
}
27-
// @ts-expect-error TS(2345): Argument of type 'null' is not assignable to param... Remove this comment to see the full error message
28-
window.history.replaceState(null, null, url.href)
10+
const orgName = groups?.find((g: any) => g.startsWith("organization:"))?.split(":")[1]
11+
12+
if (!orgName) return
13+
14+
let url = new URL(window.location.href)
15+
16+
// In non-dev environments, set the organization as subdomain
17+
if (!import.meta.env.DEV) {
18+
url.hostname = `${orgName}.${url.hostname}`
19+
window.location.href = url.href
20+
return
21+
}
22+
23+
// Check if the organization name is already in the URL path or hash then don't change it
24+
const currentPath = enableHashedRouting ? url.hash.replace("#/", "") : url.pathname
25+
const currentFirstSegment = currentPath.split("/").filter(Boolean)[0]
26+
if (orgName === currentFirstSegment) return
27+
28+
// if enableHashedRouting is true, set the hash, otherwise set the pathname
29+
const pathWithOrg = `/${orgName}`
30+
if (enableHashedRouting) {
31+
url.hash = pathWithOrg
32+
} else {
33+
url.pathname = pathWithOrg
2934
}
35+
// @ts-expect-error TS(2345): Argument of type 'null' is not assignable to param... Remove this comment to see the full error message
36+
window.history.replaceState(null, null, url.href)
3037
}
3138

3239
function resolveMockAuth(value: any) {

0 commit comments

Comments
 (0)