Merge pull request #25 from vinland100/fix/dashscope-cors-error

fix: route dashscope calls through dev proxy to avoid CORS
This commit is contained in:
lintsinghua 2025-10-30 16:00:54 +08:00 committed by GitHub
commit 83fe1ad228
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 1 deletions

View File

@ -10,7 +10,11 @@ export class QwenAdapter extends BaseLLMAdapter {
constructor(config: any) {
super(config);
this.baseUrl = config.baseUrl || 'https://dashscope.aliyuncs.com/api/v1';
if (import.meta.env.DEV) {
this.baseUrl = '/dashscope-proxy/api/v1';
} else {
this.baseUrl = config.baseUrl || 'https://dashscope.aliyuncs.com/api/v1';
}
}
async complete(request: LLMRequest): Promise<LLMResponse> {

View File

@ -51,6 +51,30 @@ export default defineConfig({
port: 5173,
host: true,
open: true,
cors: {
origin: true,
credentials: true,
methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
allowedHeaders: [
"Authorization",
"Content-Type",
"X-DashScope-SSE",
"X-Requested-With",
],
},
proxy: {
"/dashscope-proxy": {
target: "https://dashscope.aliyuncs.com",
changeOrigin: true,
secure: true,
rewrite: (path) => path.replace(/^\/dashscope-proxy/, ""),
configure: (proxy) => {
proxy.on("proxyReq", (proxyReq) => {
proxyReq.setHeader("origin", "https://dashscope.aliyuncs.com");
});
},
},
},
},
preview: {
port: 5173,