2021-02-06

Cloudflare Workers Static HTML

 06 Feb 2021  Meta Code

Cloudflare Workers Static HTML

Pass an entire HTML document as a variable in a Worker script:

async function handleRequest(request) {
  const init = {
    headers: {
      'content-type': 'text/html;charset=UTF-8',
    },
  }
  return new Response(someHTML, init)
}
addEventListener('fetch', event => {
  return event.respondWith(handleRequest(event.request))
})
const someHTML =  `
<!doctype html>
<html lang="en">
  <head>
  ...
`
Webmentions & Comments

Copyright © Paramdeo Singh. Built with Jekyll and ❤ in Guyana. All Rights Reserved.

Last Site Build on Tue, 13 Apr 2021 16:55:04 -0400

1MB Club Badge