feat: 新增可配置的路径前缀以支持子路径部署
添加前后端环境变量配置示例,新增后端路径前缀配置项,更新后端路由与静态文件挂载逻辑,调整前端代理配置与 API 调用代码,适配子路径部署场景。
This commit is contained in:
@@ -1,40 +1,46 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import { defineConfig, loadEnv } from 'vite'
|
||||
import path from 'path'
|
||||
import tailwindcss from '@tailwindcss/vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
import basicSsl from '@vitejs/plugin-basic-ssl'
|
||||
|
||||
export default defineConfig({
|
||||
base: '/app_03/',
|
||||
plugins: [
|
||||
// The React and Tailwind plugins are both required for Make, even if
|
||||
// Tailwind is not being actively used – do not remove them
|
||||
react(),
|
||||
tailwindcss(),
|
||||
// basicSsl(), // disabled for cloudflare tunnel compatibility
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
// Alias @ to the src directory
|
||||
'@': path.resolve(__dirname, './src'),
|
||||
},
|
||||
},
|
||||
export default defineConfig(({ mode }) => {
|
||||
const env = loadEnv(mode, process.cwd(), '')
|
||||
const apiPrefix = env.VITE_API_PREFIX || '/api'
|
||||
const uploadsPrefix = env.VITE_UPLOADS_PREFIX || '/uploads'
|
||||
|
||||
// File types to support raw imports. Never add .css, .tsx, or .ts files to this.
|
||||
assetsInclude: ['**/*.svg', '**/*.csv'],
|
||||
|
||||
server: {
|
||||
host: '0.0.0.0',
|
||||
allowedHosts: ['.trycloudflare.com', '.loca.lt'],
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://localhost:8000',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/uploads': {
|
||||
target: 'http://localhost:8000',
|
||||
changeOrigin: true,
|
||||
return {
|
||||
base: '/app_03/',
|
||||
plugins: [
|
||||
// The React and Tailwind plugins are both required for Make, even if
|
||||
// Tailwind is not being actively used – do not remove them
|
||||
react(),
|
||||
tailwindcss(),
|
||||
// basicSsl(), // disabled for cloudflare tunnel compatibility
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
// Alias @ to the src directory
|
||||
'@': path.resolve(__dirname, './src'),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// File types to support raw imports. Never add .css, .tsx, or .ts files to this.
|
||||
assetsInclude: ['**/*.svg', '**/*.csv'],
|
||||
|
||||
server: {
|
||||
host: '0.0.0.0',
|
||||
allowedHosts: ['.trycloudflare.com', '.loca.lt'],
|
||||
proxy: {
|
||||
[apiPrefix]: {
|
||||
target: 'http://localhost:8000',
|
||||
changeOrigin: true,
|
||||
},
|
||||
[uploadsPrefix]: {
|
||||
target: 'http://localhost:8000',
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user