addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const token = '你的token,测试token在本站找'; // 在这里填写你的 access token
const url = new URL(request.url);
const apiUrl = 'https://new.oaifree.com' + url.pathname + url.search;
// 构建新的请求
const newRequest = new Request(apiUrl, {
method: request.method,
headers: new Headers(request.headers),
});
// 在新请求中添加 Cookie
newRequest.headers.set('cookie', `access-token=${token}`);
// 向目标服务器发送请求
const response = await fetch(newRequest);
// 返回从目标服务器接收到的响应
return response;
}
反代demo可以,为什么next不行