コンテンツにスキップ

別のサイトで応答する

別のウェブサイトからの応答でWorkerリクエストに応答する (この例ではexample.com)。

export default {
async fetch(request) {
async function MethodNotAllowed(request) {
return new Response(`Method ${request.method} not allowed.`, {
status: 405,
headers: {
Allow: "GET",
},
});
}
// Only GET requests work with this proxy.
if (request.method !== "GET") return MethodNotAllowed(request);
return fetch(`https://example.com`);
},
};
Run Worker in Playground