Files
bw-mini-app/config/dev.ts
imeepos 595e56378c fix(cors): 修复H5环境下的CORS上传问题
- 在config/dev.ts中添加代理配置,将/api/*请求代理到外部API服务器
- 在bowongAISDK.ts中添加平台检测逻辑,H5环境使用fetch避免CORS
- 新增H5专用的文件上传和图像生成方法
- 保持小程序环境使用原有的Taro.uploadFile方法
- 确保跨平台兼容性,解决XMLHttpRequest凭据模式与通配符CORS头冲突

修复错误:
- Access-Control-Allow-Origin头在凭据模式下不能使用通配符*
- H5环境下uploadFile自动设置withCredentials导致的CORS阻止
2025-09-26 23:03:52 +08:00

32 lines
888 B
TypeScript

import type { UserConfigExport } from "@tarojs/cli"
export default {
mini: {},
h5: {
devServer: {
fs: {
allow: ['..']
},
proxy: {
'/api': {
target: 'https://bowongai-test--text-video-agent-fastapi-app.modal.run',
changeOrigin: true,
secure: true,
configure: (proxy, _options) => {
proxy.on('error', (err, _req, _res) => {
console.log('proxy error', err);
});
proxy.on('proxyReq', (proxyReq, req, _res) => {
console.log('Sending Request to the Target:', req.method, req.url);
});
proxy.on('proxyRes', (proxyRes, req, _res) => {
console.log('Received Response from the Target:', proxyRes.statusCode, req.url);
});
},
}
}
}
}
} satisfies UserConfigExport<'vite'>