chore: 前端首次基线提交
运行必须源码:src/、public/、index.html、package.json 及构建配置。 已忽略运行非必须:node_modules/、dist/、.env*。
This commit is contained in:
60
vite.config.js
Normal file
60
vite.config.js
Normal file
@@ -0,0 +1,60 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import { fileURLToPath, URL } from 'node:url'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
vue(),
|
||||
// 修复 Vite 内部 viteTransformMiddleware 调用 decodeURI 时遇到格式错误的 URL
|
||||
// 导致 "URI malformed" 错误的问题。在 Vite 中间件之前拦截并安全处理。
|
||||
{
|
||||
name: 'fix-uri-malformed',
|
||||
configureServer(server) {
|
||||
server.middlewares.use((req, res, next) => {
|
||||
if (req.url) {
|
||||
try {
|
||||
// 预检 URL 是否可被 decodeURI 安全解码
|
||||
decodeURI(req.url)
|
||||
} catch (_e) {
|
||||
// URL 包含无效的百分号编码序列,直接返回 400,避免进入 Vite 内部中间件
|
||||
console.warn(`[fix-uri-malformed] 拦截到格式错误的请求 URL,已返回 400`)
|
||||
res.statusCode = 400
|
||||
res.end()
|
||||
return
|
||||
}
|
||||
}
|
||||
next()
|
||||
})
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
// 开发服务器配置
|
||||
server: {
|
||||
host: '0.0.0.0',
|
||||
port: 5173,
|
||||
// 禁用 HMR 错误覆盖层,避免非致命错误(如 URI malformed)遮挡页面
|
||||
hmr: {
|
||||
overlay: false,
|
||||
},
|
||||
// 代理配置:将 /api 和 /public 请求转发到后端服务
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://127.0.0.1:7001',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/public': {
|
||||
target: 'http://127.0.0.1:7001',
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// 路径别名配置
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
||||
},
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user