mirror of
https://github.com/JefferyHcool/BiliNote.git
synced 2026-05-07 05:12:45 +08:00
- 移除 request.ts 中的重复 baseURL 配置 - 在 vite.config.ts 中添加默认的 API基地址和前端端口- 更新请求基地址为相对路径,提高可维护性
39 lines
956 B
TypeScript
39 lines
956 B
TypeScript
import { defineConfig, loadEnv } from 'vite'
|
|
import react from '@vitejs/plugin-react'
|
|
import path from 'path'
|
|
import tailwindcss from '@tailwindcss/vite'
|
|
|
|
// https://vitejs.dev/config/
|
|
export default defineConfig(({ mode }) => {
|
|
const env = loadEnv(mode, process.cwd() + '/../')
|
|
|
|
const apiBaseUrl = env.VITE_API_BASE_URL || 'http://localhost:8000'
|
|
const port = env.VITE_FRONTEND_PORT || 3015
|
|
|
|
return {
|
|
base: './',
|
|
plugins: [react(), tailwindcss()],
|
|
resolve: {
|
|
alias: {
|
|
'@': path.resolve(__dirname, './src'),
|
|
},
|
|
},
|
|
server: {
|
|
host: '0.0.0.0',
|
|
port: port,
|
|
proxy: {
|
|
'/api': {
|
|
target: apiBaseUrl,
|
|
changeOrigin: true,
|
|
rewrite: path => path.replace(/^\/api/, '/api'),
|
|
},
|
|
'/static': {
|
|
target: apiBaseUrl,
|
|
changeOrigin: true,
|
|
rewrite: path => path.replace(/^\/static/, '/static'),
|
|
},
|
|
},
|
|
},
|
|
}
|
|
})
|