From 094d4a9205c5332bccc403e130d7128b6c24d58e Mon Sep 17 00:00:00 2001 From: Devin Cowan Date: Sat, 6 Jan 2024 12:13:47 -0500 Subject: [PATCH 1/2] conditional VITE_APP_BASE --- .github/workflows/frontend-gh-pages.yml | 1 + app/env.template | 11 ++++++++--- app/frontend/Dockerfile | 2 +- app/frontend/src/auth.js | 2 +- app/frontend/vite.config.js | 10 +++++++--- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/.github/workflows/frontend-gh-pages.yml b/.github/workflows/frontend-gh-pages.yml index bfceba52..ee170446 100644 --- a/.github/workflows/frontend-gh-pages.yml +++ b/.github/workflows/frontend-gh-pages.yml @@ -44,6 +44,7 @@ jobs: echo VITE_APP_API_URL=${{ secrets.VITE_APP_API_URL }} >> .env echo VITE_APP_URL=${{ secrets.VITE_APP_URL }} >> .env echo VITE_OAUTH2_REDIRECT_URL=${{ secrets.VITE_OAUTH2_REDIRECT_URL }} >> .env + echo VITE_APP_BASE=${{ secrets.VITE_APP_BASE }} >> .env cp .env ../.env - name: Install dependencies run: npm install diff --git a/app/env.template b/app/env.template index 65ee1780..95a3117f 100644 --- a/app/env.template +++ b/app/env.template @@ -13,8 +13,13 @@ MINIO_SECRET_KEY= MINIO_API_URL=api.minio.cuahsi.io VITE_APP_NAME=subsetter -VITE_APP_ORIGIN=http://localhost:5173 -VITE_APP_BASE=/domain-subsetter/ + +# if using npm run dev, set VITE_APP_ORIGIN=http://localhost:5173 +VITE_APP_ORIGIN=https://localhost + +# for nested static deployment, set VITE_APP_BASE=/domain-subsetter/ +# VITE_APP_BASE=/domain-subsetter/ + VITE_APP_URL=${VITE_APP_ORIGIN}${VITE_APP_BASE} VITE_APP_API_HOST=localhost VITE_APP_API_URL=https://${VITE_APP_API_HOST}/api @@ -23,4 +28,4 @@ ALLOW_ORIGINS=${VITE_APP_ORIGIN} OAUTH2_REDIRECT_URL=${VITE_APP_API_URL}/auth/cuahsi/callback VITE_OAUTH2_REDIRECT_URL="${VITE_APP_URL}#/auth-redirect" -OIDC_BASE_URL=${VITE_APP_API_URL} \ No newline at end of file +OIDC_BASE_URL=https://auth.cuahsi.io/realms/CUAHSI/protocol/openid-connect/ \ No newline at end of file diff --git a/app/frontend/Dockerfile b/app/frontend/Dockerfile index cbb972db..26c3a62e 100644 --- a/app/frontend/Dockerfile +++ b/app/frontend/Dockerfile @@ -1,6 +1,6 @@ FROM node:20.9.0 as build-stage WORKDIR /app -COPY env.template ../.env +COPY .env ../.env COPY ./frontend . RUN npm update RUN npm run build diff --git a/app/frontend/src/auth.js b/app/frontend/src/auth.js index cd8f8b18..4a765cf9 100644 --- a/app/frontend/src/auth.js +++ b/app/frontend/src/auth.js @@ -12,7 +12,7 @@ export async function logIn(callback) { const authUrl = new URL(json.authorization_url) // TODO: use an env var for auth redirect instead of hard-coding // "#" hash routing was not passed from github env secret so had to hard code here. - authUrl.searchParams.set('redirect_uri', `${APP_URL}#/auth-redirect`) + authUrl.searchParams.set('redirect_uri', `${APP_URL}/#/auth-redirect`) window.open( authUrl.toString(), '_blank', diff --git a/app/frontend/vite.config.js b/app/frontend/vite.config.js index 6542afa6..6bc8f9b5 100644 --- a/app/frontend/vite.config.js +++ b/app/frontend/vite.config.js @@ -1,21 +1,25 @@ import { fileURLToPath, URL } from 'url' -import { defineConfig } from 'vite' +import { defineConfig, loadEnv } from 'vite' import vue from '@vitejs/plugin-vue' import vuetify from 'vite-plugin-vuetify' // https://vitejs.dev/config/ -export default defineConfig({ +export default defineConfig(({ mode }) => { + const env = loadEnv(mode, process.cwd()) + return { plugins: [ vue(), vuetify(), ], root: "./", - base: "/domain-subsetter/", + // for GH pages deployment, set VITE_APP_BASE=/domain-subsetter/ in .env + base: env.VITE_APP_BASE || "/", envDir: "../", resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } } +} }) From 65f5896333af748cef936ae2bc638f5a2e1bf1bc Mon Sep 17 00:00:00 2001 From: Devin Cowan Date: Sat, 6 Jan 2024 13:41:59 -0500 Subject: [PATCH 2/2] VITE_APP_FULL_URL --- .github/workflows/frontend-gh-pages.yml | 2 +- app/env.template | 21 +++++++++++++++------ app/frontend/src/auth.js | 2 +- app/frontend/src/constants.js | 2 +- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.github/workflows/frontend-gh-pages.yml b/.github/workflows/frontend-gh-pages.yml index ee170446..5e61a99f 100644 --- a/.github/workflows/frontend-gh-pages.yml +++ b/.github/workflows/frontend-gh-pages.yml @@ -42,7 +42,7 @@ jobs: run: | touch .env echo VITE_APP_API_URL=${{ secrets.VITE_APP_API_URL }} >> .env - echo VITE_APP_URL=${{ secrets.VITE_APP_URL }} >> .env + echo VITE_APP_FULL_URL=${{ secrets.VITE_APP_FULL_URL }} >> .env echo VITE_OAUTH2_REDIRECT_URL=${{ secrets.VITE_OAUTH2_REDIRECT_URL }} >> .env echo VITE_APP_BASE=${{ secrets.VITE_APP_BASE }} >> .env cp .env ../.env diff --git a/app/env.template b/app/env.template index 95a3117f..745a163e 100644 --- a/app/env.template +++ b/app/env.template @@ -18,14 +18,23 @@ VITE_APP_NAME=subsetter VITE_APP_ORIGIN=https://localhost # for nested static deployment, set VITE_APP_BASE=/domain-subsetter/ -# VITE_APP_BASE=/domain-subsetter/ +VITE_APP_BASE=/ + +# VITE_APP_FULL_URL=${VITE_APP_ORIGIN}${VITE_APP_BASE} +VITE_APP_FULL_URL=https://localhost/ -VITE_APP_URL=${VITE_APP_ORIGIN}${VITE_APP_BASE} VITE_APP_API_HOST=localhost -VITE_APP_API_URL=https://${VITE_APP_API_HOST}/api -ALLOW_ORIGINS=${VITE_APP_ORIGIN} -OAUTH2_REDIRECT_URL=${VITE_APP_API_URL}/auth/cuahsi/callback +# VITE_APP_API_URL=https://${VITE_APP_API_HOST}/api +VITE_APP_API_URL=https://localhost/api + +# ALLOW_ORIGINS=${VITE_APP_ORIGIN} +ALLOW_ORIGINS=https://localhost + +# OAUTH2_REDIRECT_URL=${VITE_APP_API_URL}/auth/cuahsi/callback +OAUTH2_REDIRECT_URL=https://localhost/api/auth/cuahsi/callback + +# VITE_OAUTH2_REDIRECT_URL="${VITE_APP_FULL_URL}#/auth-redirect" +VITE_OAUTH2_REDIRECT_URL="http://localhost/#/auth-redirect" -VITE_OAUTH2_REDIRECT_URL="${VITE_APP_URL}#/auth-redirect" OIDC_BASE_URL=https://auth.cuahsi.io/realms/CUAHSI/protocol/openid-connect/ \ No newline at end of file diff --git a/app/frontend/src/auth.js b/app/frontend/src/auth.js index 4a765cf9..cd8f8b18 100644 --- a/app/frontend/src/auth.js +++ b/app/frontend/src/auth.js @@ -12,7 +12,7 @@ export async function logIn(callback) { const authUrl = new URL(json.authorization_url) // TODO: use an env var for auth redirect instead of hard-coding // "#" hash routing was not passed from github env secret so had to hard code here. - authUrl.searchParams.set('redirect_uri', `${APP_URL}/#/auth-redirect`) + authUrl.searchParams.set('redirect_uri', `${APP_URL}#/auth-redirect`) window.open( authUrl.toString(), '_blank', diff --git a/app/frontend/src/constants.js b/app/frontend/src/constants.js index 83f97108..c5bb16c6 100644 --- a/app/frontend/src/constants.js +++ b/app/frontend/src/constants.js @@ -1,5 +1,5 @@ export const APP_NAME = import.meta.env.VITE_APP_NAME || ""; -export const APP_URL = import.meta.env.VITE_APP_URL || ""; +export const APP_URL = import.meta.env.VITE_APP_FULL_URL || ""; export const APP_BASE = import.meta.env.VITE_APP_BASE || ""; export const API_BASE = import.meta.env.VITE_APP_API_URL || "";