Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Cloudflare Docs
Log in

If you want to get started quickly, click on the button below.

Deploy to Cloudflare

This creates a repository in your GitHub account and deploys the application to Cloudflare Workers.

JavaScript
exportdefault{
asyncfetch(request,env,ctx){
// Service configured to receive logs
constLOG_URL="https://log-service.example.com/";
asyncfunctionpostLog(data){
returnawaitfetch(LOG_URL,{
method:"POST",
body:data,
});
}
letresponse;
try{
response=awaitfetch(request);
if (!response.ok&&!response.redirected){
constbody=awaitresponse.text();
thrownewError(
"Bad response at origin. Status: "+
response.status+
" Body: "+
// Ensure the string is small enough to be a header
body.trim().substring(0,10),
);
}
}catch (err){
// Without ctx.waitUntil(), your fetch() to Cloudflare's
// logging service may or may not complete
ctx.waitUntil(postLog(err.toString()));
conststack=JSON.stringify(err.stack)||err;
// Copy the response and initialize body to the stack trace
response=newResponse(stack,response);
// Add the error stack into a header to find out what happened
response.headers.set("X-Debug-stack",stack);
response.headers.set("X-Debug-err",err);
}
returnresponse;
},
};

[8]
ページ先頭

©2009-2026 Movatter.jp