Skip to content

Commit 8234de9

Browse files
committed
configure frontend service URLs via environment variables and add Nginx proxy rules for backend services in deployment.
1 parent e0c4975 commit 8234de9

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

.github/workflows/deploy-frontend.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ jobs:
9191
DOMAIN="watch.dongyuhan.com"
9292
CERT_DIR="/etc/letsencrypt/live/$DOMAIN"
9393
FRONTEND_DIR="/home/${{ secrets.FRONTEND_USER }}/app/frontend/dist"
94+
95+
# Service URLs (Matched to production requirements)
96+
PASSPORT_SERVICE_URL="http://127.0.0.1:8089"
97+
BACKEND_SERVICE_URL="http://127.0.0.1:8081"
9498
9599
# Fix permissions: Nginx needs +x on the home dir tree and 755 on the app dir
96100
sudo chmod +x /home/${{ secrets.FRONTEND_USER }}
@@ -114,6 +118,24 @@ jobs:
114118
location / {
115119
try_files \$uri \$uri/ /index.html;
116120
}
121+
122+
# Proxy to Passport Service
123+
location /api/passport/ {
124+
proxy_pass $PASSPORT_SERVICE_URL/api/v1/;
125+
proxy_set_header Host \$host;
126+
proxy_set_header X-Real-IP \$remote_addr;
127+
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
128+
proxy_set_header X-Forwarded-Proto \$scheme;
129+
}
130+
131+
# Proxy to Backend Service
132+
location /api/sev/ {
133+
proxy_pass $BACKEND_SERVICE_URL/api/v1/sev/;
134+
proxy_set_header Host \$host;
135+
proxy_set_header X-Real-IP \$remote_addr;
136+
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
137+
proxy_set_header X-Forwarded-Proto \$scheme;
138+
}
117139
}
118140
NGINX_EOF
119141
sudo cp /tmp/svcwatch_frontend.conf /etc/nginx/conf.d/svcwatch-frontend.conf

frontend/vite.config.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import { fileURLToPath, URL } from 'node:url'
22

3-
import { defineConfig } from 'vite'
3+
import { defineConfig, loadEnv } from 'vite'
44
import vue from '@vitejs/plugin-vue'
55
import vueDevTools from 'vite-plugin-vue-devtools'
66

7-
// Service URLs
8-
const PASSPORT_SERVICE_URL = 'http://127.0.0.1:8089'
9-
const BACKEND_SERVICE_URL = 'http://127.0.0.1:8080'
10-
117
// https://vite.dev/config/
12-
export default defineConfig({
8+
export default defineConfig(({ mode }) => {
9+
// Load env file based on `mode` in the current working directory.
10+
// Set the third parameter to '' to load all env regardless of the `VITE_` prefix.
11+
const env = loadEnv(mode, process.cwd(), '')
12+
13+
// Service URLs
14+
const PASSPORT_SERVICE_URL = env.VITE_PASSPORT_SERVICE_URL || 'http://127.0.0.1:8089'
15+
const BACKEND_SERVICE_URL = env.VITE_BACKEND_SERVICE_URL || 'http://127.0.0.1:8080'
16+
17+
return {
1318
plugins: [
1419
vue(),
1520
vueDevTools(),
@@ -38,4 +43,5 @@ export default defineConfig({
3843
},
3944
},
4045
},
46+
}
4147
})

frontend/vitest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { mergeConfig, defineConfig, configDefaults } from 'vitest/config'
33
import viteConfig from './vite.config'
44

55
export default mergeConfig(
6-
viteConfig,
6+
typeof viteConfig === 'function' ? viteConfig({ mode: 'test', command: 'serve', isSsrBuild: false, isPreview: false }) : viteConfig,
77
defineConfig({
88
test: {
99
environment: 'jsdom',

0 commit comments

Comments
 (0)