Skip to content

Commit

Permalink
conditional VITE_APP_BASE
Browse files Browse the repository at this point in the history
  • Loading branch information
devincowan committed Jan 6, 2024
1 parent 7e63ff9 commit 3549ca2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/frontend-gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions app/env.template
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
OIDC_BASE_URL=https://auth.cuahsi.io/realms/CUAHSI/protocol/openid-connect/
2 changes: 1 addition & 1 deletion app/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/frontend/src/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
10 changes: 7 additions & 3 deletions app/frontend/vite.config.js
Original file line number Diff line number Diff line change
@@ -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))
}
}
}
})

0 comments on commit 3549ca2

Please sign in to comment.