skiy
2023-04-24 13:00:48 +08:00
只是用接口的,用 cloudflare workers 中转一下就好了…
export interface Env {
WEB_URL: string;
}
export default {
async fetch(request: Request, env: Env) {
const API_URL = `${env.WEB_URL}`;
const url = new URL(request.url);
url.host = API_URL.replace(/^https?:\/\//, '');
const modifiedRequest = new Request(url.toString(), {
headers: request.headers,
method: request.method,
body: request.body,
redirect: 'follow',
});
const response = await fetch(modifiedRequest);
const modifiedResponse = new Response(response.body, response);
// 添加允许跨域访问的响应头
modifiedResponse.headers.set('Access-Control-Allow-Origin', '*');
return modifiedResponse;
},
};