From 3549ca21f207be3d12e13f43e2ee3593b57de3ec Mon Sep 17 00:00:00 2001 From: Devin Cowan Date: Sat, 6 Jan 2024 11:38:54 -0500 Subject: [PATCH] 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..0c748de9 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.APP_BASE || "/", envDir: "../", resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } } +} })