blob: ae9a27fddd3bbe384a0a79ea14961b93d9fd63ce [file] [log] [blame]
vulgar5201ef2b41e2025-06-05 19:09:44 +08001// vue.config.js
Xing Jinwenff16b1e2025-06-05 00:29:26 +08002const { defineConfig } = require('@vue/cli-service')
3
4module.exports = defineConfig({
5 transpileDependencies: true,
vulgar5201ef2b41e2025-06-05 19:09:44 +08006
7 /* dev 服务只跑在 8080;真正的后端地址改用
8 环境变量 VUE_APP_BACKEND,默认仍指向 8081 */
Xing Jinwenff16b1e2025-06-05 00:29:26 +08009 devServer: {
10 port: 8080,
11 proxy: {
vulgar5201ef2b41e2025-06-05 19:09:44 +080012 // ❶ 统一以 /api 开头的请求全部反向代理
Xing Jinwenff16b1e2025-06-05 00:29:26 +080013 '/api': {
vulgar5201ef2b41e2025-06-05 19:09:44 +080014 target: process.env.VUE_APP_BACKEND || 'http://localhost:8081',
Xing Jinwenff16b1e2025-06-05 00:29:26 +080015 changeOrigin: true,
16 ws: true,
vulgar5201c4a15b12025-06-06 13:55:09 +080017 secure: false,
18 logLevel: 'debug',
19 onProxyReq: (proxyReq, req, res) => {
20 console.log('🔄 代理请求:', req.method, req.url, '→', 'http://localhost:8081' + req.url)
21 },
22 onProxyRes: (proxyRes, req, res) => {
23 console.log('📨 代理响应:', proxyRes.statusCode, req.url)
24 },
25 onError: (err, req, res) => {
26 console.error('❌ 代理错误:', err.message)
27 }
28 },// 这里需要闭合 /api 的配置
vulgar5201ef2b41e2025-06-05 19:09:44 +080029
30 /* ❷ 可选:如果你项目里还有没改完的
31 /category、/torrent、/auth 旧写法,保留兼容性。
32 改完之后,把这一段删掉也行。 */
vulgar5201055346a2025-06-05 14:15:55 +080033 '/category': {
vulgar5201ef2b41e2025-06-05 19:09:44 +080034 target: process.env.VUE_APP_BACKEND || 'http://localhost:8081',
vulgar5201055346a2025-06-05 14:15:55 +080035 changeOrigin: true,
vulgar5201ef2b41e2025-06-05 19:09:44 +080036 pathRewrite: { '^/category': '/api/category' }
vulgar5201055346a2025-06-05 14:15:55 +080037 },
38 '/torrent': {
vulgar5201ef2b41e2025-06-05 19:09:44 +080039 target: process.env.VUE_APP_BACKEND || 'http://localhost:8081',
vulgar5201055346a2025-06-05 14:15:55 +080040 changeOrigin: true,
vulgar5201ef2b41e2025-06-05 19:09:44 +080041 pathRewrite: { '^/torrent': '/api/torrent' }
vulgar5201055346a2025-06-05 14:15:55 +080042 },
43 '/auth': {
vulgar5201ef2b41e2025-06-05 19:09:44 +080044 target: process.env.VUE_APP_BACKEND || 'http://localhost:8081',
vulgar5201055346a2025-06-05 14:15:55 +080045 changeOrigin: true,
vulgar5201ef2b41e2025-06-05 19:09:44 +080046 pathRewrite: { '^/auth': '/api/auth' }
Xing Jinwenff16b1e2025-06-05 00:29:26 +080047 }
48 }
49 }
vulgar5201c4a15b12025-06-06 13:55:09 +080050})