Welcome to Cloudflare
Build with Cloudflare
Run Worker
export default { async fetch ( request ) { const html = ` <! DOCTYPE html> <body> <h1>Hello World</h1> <p>This markup was generated by a Cloudflare Worker.</ p> </body> ` ; return new Response ( html , { headers : { "content-type" : "text/html; charset=UTF-8" , } , } ) ; } , } ;
Run Worker
export default { async fetch ( request ) { const data = { hello : "world" , } ; return Response . json ( data ) ; } , } ;
Run Worker
export default { async fetch ( request ) { /** * Replace `remote` with the host you wish to send requests to */ const remote = " https://example.com " ; return await fetch ( remote , request ) ; } , } ;
Run Worker
export default { async fetch ( request ) { const destinationURL = " https://example.com " ; const statusCode = three hundred and one ; return Response . redirect ( destinationURL , statusCode ) ; } , } ;
Run Worker
export default { async fetch ( request ) { async function MethodNotAllowed ( request ) { return new Response ( ` Method ${ request . method } not allowed. ` , { status : four hundred and five , headers : { Allow : "GET" , } , } ) ; } // Only GET requests work with this proxy. if ( request . method !== "GET" ) return MethodNotAllowed ( request ) ; return fetch ( ` https://example.com ` ) ; } , } ;
Developer Platform
Zero Trust
Other docs you might also like
Community
Open source