feat(admin): set /admin base path for reverse proxy deployment

Configure Vite base, Vue Router history, axios baseURL and container
Nginx to serve the admin panel under /admin/ path prefix.

🤖 Generated with [Qoder][https://qoder.com]
This commit is contained in:
2026-06-09 09:18:16 +08:00
parent 5279a7f831
commit b1ef7dc6f9
5 changed files with 25 additions and 7 deletions

View File

@@ -3,7 +3,7 @@ import router from './router';
import { clearStaffSession, reconcileStaffSessionFromToken, useAuthStore } from './stores/auth';
import { ensureStaffSession, resetStaffSessionHydration } from './utils/session-hydrate';
const api = axios.create({ baseURL: '/api' });
const api = axios.create({ baseURL: '/admin/api' });
let handling401 = false;
let handling403Portal = false;

View File

@@ -3,7 +3,7 @@ import { useAuthStore } from '../stores/auth';
import { ensureStaffSession } from '../utils/session-hydrate';
const router = createRouter({
history: createWebHistory(),
history: createWebHistory('/admin'),
routes: [
{ path: '/login', component: () => import('../views/Login.vue'), meta: { public: true } },
{

View File

@@ -3,6 +3,7 @@ import vue from '@vitejs/plugin-vue';
import { resolve } from 'path';
export default defineConfig({
base: '/admin/',
plugins: [vue()],
resolve: {
// 避免 src 内遗留的 .js 抢先于 .ts/.vue 被解析(曾导致 i18n 文案缺失)
@@ -15,6 +16,12 @@ export default defineConfig({
publicDir: resolve(__dirname, '../../packages/shared/public'),
server: {
port: 5174,
proxy: { '/api': { target: 'http://localhost:3000', changeOrigin: true } },
proxy: {
'/admin/api': {
target: 'http://localhost:3000',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/admin\/api/, '/api'),
},
},
},
});

8
apps/api/.env Normal file
View File

@@ -0,0 +1,8 @@
DATABASE_URL=postgresql://thebet365:thebet365@localhost:5432/thebet365
REDIS_URL=redis://localhost:6379
JWT_SECRET=dev-secret-change-in-production
JWT_PLAYER_EXPIRES=24h
JWT_ADMIN_EXPIRES=2h
JWT_AGENT_EXPIRES=8h
PORT=3000
NODE_ENV=development

View File

@@ -9,9 +9,8 @@ server {
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml;
location /api/ {
set $api_upstream api:3000;
proxy_pass http://$api_upstream;
location /admin/api/ {
proxy_pass http://api:3000/api/;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
@@ -19,7 +18,11 @@ server {
proxy_set_header X-Forwarded-Proto $scheme;
}
location /admin/ {
try_files $uri $uri/ /admin/index.html;
}
location / {
try_files $uri $uri/ /index.html;
return 301 /admin/;
}
}