Skip to content

Commit c1e1f24

Browse files
committed
🐛fix: CROS
1 parent 71f0c23 commit c1e1f24

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
<p>Serverless API Proxy: Multi-API Proxy Gateway Based on Vercel Routes, Cloudflare Workers, and Netlify Redirects</p>
77
</div>
88

9+
## Notice
10+
11+
**Due to login restrictions on the original account([lopins](https://github.com/lopins)), I'm now using this account([lopinx](https://github.com/lopinx)) for maintenance purposes.**
12+
913
## Support
1014

1115
- openai

README_CN.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
<p>Serverless API Proxy: 基于Vercel Routes、Cloudflare Worker、Netlify Redirects的多API代理网关</p>
77
</div>
88

9+
## 特别提示
10+
11+
**原账号([lopins](https://github.com/lopins))由于被限制登录,现在使用本账号([lopinx](https://github.com/lopinx))维护**
12+
913
## 支持服务
1014

1115
- openai

src/_worker.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async function handleRequest(request) {
5353
const [prefix, rest] = extractPrefixAndRest(pathname, Object.keys(apiMapping));
5454
if (prefix) {
5555
const baseApiUrl = apiMapping[prefix];
56-
const targetUrl = `${baseApiUrl}${rest}`;
56+
const targetUrl = new URL(`${baseApiUrl}${rest}`);
5757
queryParams.forEach((value, key) => targetUrl.searchParams.append(key, value));
5858

5959
try {
@@ -64,7 +64,9 @@ async function handleRequest(request) {
6464
});
6565

6666
const response = await fetch(newRequest);
67-
return response;
67+
const modifiedResponse = new Response(response.body, response);
68+
['Access-Control-Allow-Origin', 'Access-Control-Allow-Methods', 'Access-Control-Allow-Headers'].forEach(header => modifiedResponse.headers.set(header, '*'));
69+
return modifiedResponse;
6870
} catch (error) {
6971
console.error('Failed to fetch:', error);
7072
return new Response('Internal Server Error', { status: 500 });

0 commit comments

Comments
 (0)