mirror of
https://gitee.com/myxzgzs/boyue-kfcode-hasfj.git
synced 2025-06-21 05:59:36 +08:00
75 lines
2.1 KiB
TypeScript
75 lines
2.1 KiB
TypeScript
import { fileURLToPath, URL } from 'node:url'
|
||
import fs from 'node:fs'
|
||
import path from 'node:path'
|
||
|
||
import { defineConfig } from 'vite'
|
||
import vue from '@vitejs/plugin-vue'
|
||
import vueDevTools from 'vite-plugin-vue-devtools'
|
||
|
||
// https://vite.dev/config/
|
||
export default defineConfig({
|
||
plugins: [
|
||
vue(),
|
||
vueDevTools(),
|
||
// 自定义中间件,处理路由问题
|
||
{
|
||
name: 'handle-spa-fallback',
|
||
configureServer(server) {
|
||
// 返回中间件处理函数
|
||
return () => {
|
||
server.middlewares.use((req, res, next) => {
|
||
// 如果是前端路由路径,直接返回index.html
|
||
if (req.url === '/hasfjlaw' || req.url === '/hasfjcase' || req.url === '/hasfjform' || req.url === '/qrcodes') {
|
||
const indexHtml = fs.readFileSync(
|
||
path.resolve(__dirname, 'index.html'),
|
||
'utf-8'
|
||
)
|
||
res.statusCode = 200
|
||
res.setHeader('Content-Type', 'text/html')
|
||
res.end(indexHtml)
|
||
return
|
||
}
|
||
next()
|
||
})
|
||
}
|
||
}
|
||
}
|
||
],
|
||
resolve: {
|
||
alias: {
|
||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||
},
|
||
},
|
||
server: {
|
||
port: 80, // 指定端口为80
|
||
host: '0.0.0.0', // 允许外部访问
|
||
proxy: {
|
||
// 配置跨域
|
||
'/api': {
|
||
target: 'http://222.184.49.22:9799', // 后端服务地址
|
||
changeOrigin: true, // 支持跨域
|
||
rewrite: (path) => path.replace(/^\/api/, '') // 移除/api前缀
|
||
},
|
||
// 添加司法局后台管理接口代理
|
||
'/hasfj': {
|
||
target: 'http://222.184.49.22:9799', // 司法局后端服务
|
||
changeOrigin: true,
|
||
rewrite: (path) => path // 保持路径不变
|
||
},
|
||
// // 详情页面代理
|
||
// '/show.html': {
|
||
// target: 'http://localhost:9799',
|
||
// changeOrigin: true
|
||
// },
|
||
// '/showcase.html': {
|
||
// target: 'http://localhost:9799',
|
||
// changeOrigin: true
|
||
// },
|
||
// '/table.html': {
|
||
// target: 'http://localhost:9799',
|
||
// changeOrigin: true
|
||
// }
|
||
}
|
||
}
|
||
})
|