fix(config): 修复API代理配置和认证密码问题
- 修改auth.js中的默认密码为安全密码admin123 - 移除request.js中的baseURL配置避免重复前缀 - 在请求拦截器中统一添加/api前缀逻辑 - 简化vite.config.js中的代理配置,使用重写规则替代多个重复配置
This commit is contained in:
@@ -26,7 +26,7 @@ export async function autoLogin() {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
username: 'admin',
|
||||
password: 'FAD888888'
|
||||
password: 'admin123'
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import axios from 'axios'
|
||||
|
||||
// 走 Nginx 代理,同域名请求
|
||||
const baseURL = '/api'
|
||||
|
||||
const service = axios.create({
|
||||
baseURL: baseURL,
|
||||
timeout: 30000
|
||||
})
|
||||
|
||||
@@ -25,6 +21,12 @@ const getToken = () => {
|
||||
|
||||
service.interceptors.request.use(
|
||||
config => {
|
||||
// 统一加 /api 前缀(生产环境 Nginx 代理用,开发环境 Vite 代理用)
|
||||
// 如果 URL 已带 /api/ 或已是绝对地址,则跳过
|
||||
if (!config.url.startsWith('/api/') && !config.url.startsWith('http')) {
|
||||
config.url = '/api' + config.url
|
||||
}
|
||||
|
||||
const token = getToken()
|
||||
|
||||
if (token) {
|
||||
|
||||
@@ -13,31 +13,8 @@ export default defineConfig({
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://localhost:8080',
|
||||
changeOrigin: true
|
||||
},
|
||||
'/da': {
|
||||
target: 'http://localhost:8080',
|
||||
changeOrigin: true
|
||||
},
|
||||
'/pocket': {
|
||||
target: 'http://localhost:8080',
|
||||
changeOrigin: true
|
||||
},
|
||||
'/l2': {
|
||||
target: 'http://localhost:8080',
|
||||
changeOrigin: true
|
||||
},
|
||||
'/wms': {
|
||||
target: 'http://localhost:8080',
|
||||
changeOrigin: true
|
||||
},
|
||||
'/oee': {
|
||||
target: 'http://localhost:8080',
|
||||
changeOrigin: true
|
||||
},
|
||||
'/crm': {
|
||||
target: 'http://localhost:8080',
|
||||
changeOrigin: true
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(/^\/api/, '')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user