Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-hodgson committed Mar 4, 2025
1 parent 32a8400 commit 43124a4
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 29 deletions.
1 change: 1 addition & 0 deletions apps/synapse-oauth-signin/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Environment variables shared by all stacks, can be overridden by adding new values to .env.<mode> files.
2 changes: 2 additions & 0 deletions apps/synapse-oauth-signin/.env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VITE_SYNAPSE_REPO_ENDPOINT=https://repo-dev.dev.sagebase.org
VITE_SYNAPSE_PORTAL_ENDPOINT=https://dev.synapse.org
4 changes: 4 additions & 0 deletions apps/synapse-oauth-signin/.env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This extends .env, vars shared between prod and staging should go there!

VITE_SYNAPSE_REPO_ENDPOINT=https://repo-prod.prod.sagebase.org
VITE_SYNAPSE_PORTAL_ENDPOINT=https://www.synapse.org
4 changes: 4 additions & 0 deletions apps/synapse-oauth-signin/.env.staging
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This extends .env, vars shared between prod and staging should go there!

VITE_SYNAPSE_REPO_ENDPOINT=https://repo-staging.prod.sagebase.org
VITE_SYNAPSE_PORTAL_ENDPOINT=https://staging.synapse.org
10 changes: 10 additions & 0 deletions apps/synapse-oauth-signin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@

globalThis.global = globalThis
</script>
<script>
const endpointOverride = {
REPO: "%VITE_SYNAPSE_REPO_ENDPOINT%",
PORTAL: "%VITE_SYNAPSE_PORTAL_ENDPOINT%"
}

if (endpointOverride.REPO && endpointOverride.PORTAL) {
window.SRC_OVERRIDE_ENDPOINT_CONFIG = endpointOverride;
}
</script>
<script type="module" src="./src/index.tsx"></script>
</head>
<body id="body">
Expand Down
2 changes: 1 addition & 1 deletion apps/synapse-oauth-signin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
},
"scripts": {
"clean": "rimraf build coverage",
"start": "vite",
"start": "echo \"WARNING!: running pnpm start now causes Vite to point to the Synapse dev stack. To point to production, run pnpm start --mode=production\n\"; vite",
"build": "vite build",
"test": "vitest",
"lint": "eslint src",
Expand Down
28 changes: 0 additions & 28 deletions apps/synapse-oauth-signin/src/AppInitializer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,6 @@ function AppInitializer(props: PropsWithChildren<Record<string, unknown>>) {
maxAge = parseInt(maxAgeURLParam)
}
const clientId = searchParams.get('client_id') ?? undefined

useEffect(() => {
// can override endpoints as https://repo-staging.prod.sagebase.org/ and https://staging.synapse.org for staging

const isStaging: boolean = window.location.hostname.includes('staging')
const isDev: boolean = window.location.hostname.includes('dev')

const stagingConfig = {
REPO: SynapseConstants.SYNAPSE_BACKEND_STAGING_URL,
PORTAL: 'https://staging.synapse.org/',
}

const devConfig = {
REPO: SynapseConstants.SYNAPSE_BACKEND_DEV_URL,
PORTAL: 'https://dev.synapse.org/',
}

if (isStaging || isDev) {
if (!(window as any).SRC) {
;(window as any).SRC = {}
}

;(window as any).SRC_OVERRIDE_ENDPOINT_CONFIG = isStaging
? stagingConfig
: devConfig
}
}, [])

const onNoAccessTokenFound = useCallback(() => {
if (prompt === 'none') {
// not logged in, and prompt is "none".
Expand Down
10 changes: 10 additions & 0 deletions apps/synapse-oauth-signin/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/// <reference types="vite/client" />

interface ImportMetaEnv {
readonly VITE_SYNAPSE_REPO_ENDPOINT: string
readonly VITE_SYNAPSE_PORTAL_ENDPOINT: string
}

interface ImportMeta {
readonly env: ImportMetaEnv
}

0 comments on commit 43124a4

Please sign in to comment.