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:
commit
83fe1ad228
|
|
@ -10,8 +10,12 @@ export class QwenAdapter extends BaseLLMAdapter {
|
||||||
|
|
||||||
constructor(config: any) {
|
constructor(config: any) {
|
||||||
super(config);
|
super(config);
|
||||||
|
if (import.meta.env.DEV) {
|
||||||
|
this.baseUrl = '/dashscope-proxy/api/v1';
|
||||||
|
} else {
|
||||||
this.baseUrl = config.baseUrl || 'https://dashscope.aliyuncs.com/api/v1';
|
this.baseUrl = config.baseUrl || 'https://dashscope.aliyuncs.com/api/v1';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async complete(request: LLMRequest): Promise<LLMResponse> {
|
async complete(request: LLMRequest): Promise<LLMResponse> {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,30 @@ export default defineConfig({
|
||||||
port: 5173,
|
port: 5173,
|
||||||
host: true,
|
host: true,
|
||||||
open: 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: {
|
preview: {
|
||||||
port: 5173,
|
port: 5173,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue