Files
yml2213 970bae16d1 修复访客浏览轨迹延迟与排序,增加演示站
保留 SPA hash 以正确区分页面;延迟采集 title 避免慢一页;轨迹改为最新在上;补充 demo-shop 测试页与 Vite 静态路由。
2026-07-18 23:22:47 +08:00

44 lines
1.2 KiB
TypeScript

import { defineConfig, type Plugin } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
import path from 'path'
/** 避免 /demo-shop/ 被 SPA 回退成 React,导致 404;改为提供 public 静态页 */
function demoShopStatic(): Plugin {
return {
name: 'demo-shop-static',
configureServer(server) {
// 必须挂在内部中间件之前,否则会先进 React SPA
server.middlewares.use((req, _res, next) => {
const raw = req.url || ''
const pathname = raw.split('?')[0]
if (pathname === '/demo-shop' || pathname === '/demo-shop/') {
const qs = raw.includes('?') ? raw.slice(raw.indexOf('?')) : ''
req.url = `/demo-shop/index.html${qs}`
}
next()
})
},
}
}
export default defineConfig({
plugins: [react(), tailwindcss(), demoShopStatic()],
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
server: {
proxy: {
// 显式开启 WebSocket 代理,确保 /api/ws、/api/widget/ws 在开发环境可升级
'/api': {
target: 'http://localhost:8080',
changeOrigin: true,
ws: true,
},
'/health': 'http://localhost:8080',
},
},
})