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:
@@ -3,7 +3,7 @@ import router from './router';
|
|||||||
import { clearStaffSession, reconcileStaffSessionFromToken, useAuthStore } from './stores/auth';
|
import { clearStaffSession, reconcileStaffSessionFromToken, useAuthStore } from './stores/auth';
|
||||||
import { ensureStaffSession, resetStaffSessionHydration } from './utils/session-hydrate';
|
import { ensureStaffSession, resetStaffSessionHydration } from './utils/session-hydrate';
|
||||||
|
|
||||||
const api = axios.create({ baseURL: '/api' });
|
const api = axios.create({ baseURL: '/admin/api' });
|
||||||
|
|
||||||
let handling401 = false;
|
let handling401 = false;
|
||||||
let handling403Portal = false;
|
let handling403Portal = false;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { useAuthStore } from '../stores/auth';
|
|||||||
import { ensureStaffSession } from '../utils/session-hydrate';
|
import { ensureStaffSession } from '../utils/session-hydrate';
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
history: createWebHistory(),
|
history: createWebHistory('/admin'),
|
||||||
routes: [
|
routes: [
|
||||||
{ path: '/login', component: () => import('../views/Login.vue'), meta: { public: true } },
|
{ path: '/login', component: () => import('../views/Login.vue'), meta: { public: true } },
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import vue from '@vitejs/plugin-vue';
|
|||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
|
base: '/admin/',
|
||||||
plugins: [vue()],
|
plugins: [vue()],
|
||||||
resolve: {
|
resolve: {
|
||||||
// 避免 src 内遗留的 .js 抢先于 .ts/.vue 被解析(曾导致 i18n 文案缺失)
|
// 避免 src 内遗留的 .js 抢先于 .ts/.vue 被解析(曾导致 i18n 文案缺失)
|
||||||
@@ -15,6 +16,12 @@ export default defineConfig({
|
|||||||
publicDir: resolve(__dirname, '../../packages/shared/public'),
|
publicDir: resolve(__dirname, '../../packages/shared/public'),
|
||||||
server: {
|
server: {
|
||||||
port: 5174,
|
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
8
apps/api/.env
Normal 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
|
||||||
@@ -9,9 +9,8 @@ server {
|
|||||||
gzip on;
|
gzip on;
|
||||||
gzip_types text/plain text/css application/json application/javascript text/xml application/xml;
|
gzip_types text/plain text/css application/json application/javascript text/xml application/xml;
|
||||||
|
|
||||||
location /api/ {
|
location /admin/api/ {
|
||||||
set $api_upstream api:3000;
|
proxy_pass http://api:3000/api/;
|
||||||
proxy_pass http://$api_upstream;
|
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
@@ -19,7 +18,11 @@ server {
|
|||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
location /admin/ {
|
||||||
|
try_files $uri $uri/ /admin/index.html;
|
||||||
|
}
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
try_files $uri $uri/ /index.html;
|
return 301 /admin/;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user