我正在使用由HTTP请求触发的Cloudflare worker。我想接收传入的请求,更改URL,但保持所有其他属性不变,然后发出请求。结构如下:
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
#change the value of request.url and then...
return fetch(request)
.then(response => {
return response;
});
}
您可以这样做:
async function handleRequest(request) {
#change the value of request.url and then...
return fetch({...request, url: "someUrl"})
.then(response => {
return response;
});
}
这将用“ someUrl”覆盖网址希望这会有所帮助:)