2025-04-14 10:57:27 +08:00
|
|
|
import { fileURLToPath, URL } from 'node:url'
|
|
|
|
|
|
|
|
|
|
import { defineConfig } from 'vite'
|
|
|
|
|
import vue from '@vitejs/plugin-vue'
|
|
|
|
|
import Components from 'unplugin-vue-components/vite';
|
|
|
|
|
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
|
|
|
|
|
|
2025-10-10 11:28:15 +08:00
|
|
|
let targetUrl = 'http://192.168.2.226:10010/'
|
|
|
|
|
// targetUrl = 'http://192.168.2.142:10010/'
|
2025-08-08 10:59:34 +08:00
|
|
|
|
|
|
|
|
// 测试服
|
|
|
|
|
// targetUrl = 'https://www.cdzhuojing.cn/'
|
|
|
|
|
|
|
|
|
|
// 正式服
|
|
|
|
|
targetUrl = 'https://www.cx.cdzhuojing.cn/'
|
|
|
|
|
|
2025-04-14 10:57:27 +08:00
|
|
|
// https://vite.dev/config/
|
|
|
|
|
export default defineConfig({
|
|
|
|
|
plugins: [
|
|
|
|
|
vue()
|
|
|
|
|
, Components({
|
|
|
|
|
resolvers: [AntDesignVueResolver({
|
|
|
|
|
importStyle: 'less',// 启用LESS主题定制
|
|
|
|
|
resolveIcons: true
|
|
|
|
|
})],
|
|
|
|
|
})
|
|
|
|
|
],
|
|
|
|
|
resolve: {
|
|
|
|
|
alias: {
|
|
|
|
|
'@': fileURLToPath(new URL('./src', import.meta.url))
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
base: './',
|
|
|
|
|
build: {
|
|
|
|
|
assetsDir: 'assets'
|
|
|
|
|
},
|
|
|
|
|
server: {
|
|
|
|
|
proxy: {
|
2025-10-10 11:28:15 +08:00
|
|
|
// '^/ebike/operate/*'
|
2025-05-29 10:43:15 +08:00
|
|
|
'^/ebike/operate/*': {
|
2025-04-14 10:57:27 +08:00
|
|
|
changeOrigin: true,
|
2025-04-27 18:22:46 +08:00
|
|
|
target: targetUrl,
|
2025-10-10 11:28:15 +08:00
|
|
|
secure: false,
|
2025-04-14 10:57:27 +08:00
|
|
|
rewrite: (path) => {
|
|
|
|
|
return path.replace(/^\/operate/, 'operate')
|
|
|
|
|
}
|
2025-10-10 11:28:15 +08:00
|
|
|
, bypass(req, res, options) {
|
|
|
|
|
//@ts-ignore
|
|
|
|
|
const proxyUrl = new URL(options.rewrite(req.url) || '', (options.target))?.href || '';
|
|
|
|
|
console.log(proxyUrl);
|
|
|
|
|
req.headers['x-req-proxyUrl'] = proxyUrl
|
|
|
|
|
res.setHeader('x-res-proxyUrl', proxyUrl)
|
|
|
|
|
}
|
2025-04-14 10:57:27 +08:00
|
|
|
},
|
2025-10-10 11:28:15 +08:00
|
|
|
// '^/ebike/maintenance/*'
|
2025-05-29 10:43:15 +08:00
|
|
|
'^/ebike/maintenance/*': {
|
2025-04-14 10:57:27 +08:00
|
|
|
changeOrigin: true,
|
2025-04-27 18:22:46 +08:00
|
|
|
target: targetUrl,
|
2025-10-10 11:28:15 +08:00
|
|
|
secure: false,
|
2025-04-14 10:57:27 +08:00
|
|
|
rewrite: (path) => {
|
|
|
|
|
return path.replace(/^\/maintenance/, 'maintenance')
|
|
|
|
|
}
|
2025-10-10 11:28:15 +08:00
|
|
|
, bypass(req, res, options) {
|
|
|
|
|
//@ts-ignore
|
|
|
|
|
const proxyUrl = new URL(options.rewrite(req.url) || '', (options.target))?.href || '';
|
|
|
|
|
console.log(proxyUrl);
|
|
|
|
|
req.headers['x-req-proxyUrl'] = proxyUrl
|
|
|
|
|
res.setHeader('x-res-proxyUrl', proxyUrl)
|
|
|
|
|
}
|
2025-04-14 10:57:27 +08:00
|
|
|
},
|
2025-10-10 11:28:15 +08:00
|
|
|
// ^/ebike/user/*
|
2025-05-29 10:43:15 +08:00
|
|
|
'^/ebike/user/*': {
|
2025-04-14 10:57:27 +08:00
|
|
|
changeOrigin: true,
|
2025-04-27 18:22:46 +08:00
|
|
|
target: targetUrl,
|
2025-10-10 11:28:15 +08:00
|
|
|
secure: false,
|
2025-04-14 10:57:27 +08:00
|
|
|
rewrite: (path) => {
|
|
|
|
|
return path.replace(/^\/user/, 'user')
|
|
|
|
|
}
|
2025-10-10 11:28:15 +08:00
|
|
|
, bypass(req, res, options) {
|
|
|
|
|
//@ts-ignore
|
|
|
|
|
const proxyUrl = new URL(options.rewrite(req.url) || '', (options.target))?.href || '';
|
|
|
|
|
console.log(proxyUrl);
|
|
|
|
|
req.headers['x-req-proxyUrl'] = proxyUrl
|
|
|
|
|
res.setHeader('x-res-proxyUrl', proxyUrl)
|
|
|
|
|
}
|
2025-04-17 18:31:22 +08:00
|
|
|
},
|
2025-10-10 11:28:15 +08:00
|
|
|
// '^/ebike/order/*'
|
2025-05-29 10:43:15 +08:00
|
|
|
'^/ebike/order/*': {
|
2025-04-17 18:31:22 +08:00
|
|
|
changeOrigin: true,
|
2025-04-27 18:22:46 +08:00
|
|
|
target: targetUrl,
|
2025-10-10 11:28:15 +08:00
|
|
|
secure: false,
|
2025-04-17 18:31:22 +08:00
|
|
|
rewrite: (path) => {
|
|
|
|
|
return path.replace(/^\/order/, 'order')
|
|
|
|
|
}
|
2025-10-10 11:28:15 +08:00
|
|
|
, bypass(req, res, options) {
|
|
|
|
|
//@ts-ignore
|
|
|
|
|
const proxyUrl = new URL(options.rewrite(req.url) || '', (options.target))?.href || '';
|
|
|
|
|
console.log(proxyUrl);
|
|
|
|
|
req.headers['x-req-proxyUrl'] = proxyUrl
|
|
|
|
|
res.setHeader('x-res-proxyUrl', proxyUrl)
|
|
|
|
|
}
|
2025-05-23 17:44:38 +08:00
|
|
|
},
|
2025-10-10 11:28:15 +08:00
|
|
|
// '^/ebike/payment/*'
|
2025-05-29 10:43:15 +08:00
|
|
|
'^/ebike/payment/*': {
|
2025-05-23 17:44:38 +08:00
|
|
|
changeOrigin: true,
|
|
|
|
|
target: targetUrl,
|
2025-10-10 11:28:15 +08:00
|
|
|
secure: false,
|
2025-05-23 17:44:38 +08:00
|
|
|
rewrite: (path) => {
|
|
|
|
|
return path.replace(/^\/order/, 'payment')
|
2025-10-10 11:28:15 +08:00
|
|
|
},
|
|
|
|
|
bypass(req, res, options) {
|
|
|
|
|
//@ts-ignore
|
|
|
|
|
const proxyUrl = new URL(options.rewrite(req.url) || '', (options.target))?.href || '';
|
|
|
|
|
console.log(proxyUrl);
|
|
|
|
|
req.headers['x-req-proxyUrl'] = proxyUrl
|
|
|
|
|
res.setHeader('x-res-proxyUrl', proxyUrl)
|
2025-05-23 17:44:38 +08:00
|
|
|
}
|
2025-04-14 10:57:27 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
cors: true,
|
|
|
|
|
host: '0.0.0.0'
|
|
|
|
|
}
|
|
|
|
|
})
|