Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Last active November 20, 2018 19:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WebReflection/6d4a9ee1fd4cb98e457c7705af880a39 to your computer and use it in GitHub Desktop.
Save WebReflection/6d4a9ee1fd4cb98e457c7705af880a39 to your computer and use it in GitHub Desktop.
hyperHTML does Cloudflare Worker
const basicHTML = require('basichtml');
basicHTML.init();
document.documentElement.setAttribute('lang', 'en');
const {bind} = require('hyperhtml');
const model = {
index: {
title: 'hyperHTML does Cloudflare too',
h1: {
text: '🍾 Cloudflare hyperHTML Worker 🎉'
}
}
};
const render = {
index: model => bind(document.documentElement)
`<head>
<title>${model.title}</title>
<meta name=viewport content="width=device-width">
<meta name="theme-color" content="#ffffff">
</head>
<body>
<h1>${model.h1.text}</h1>
<main></main>
</body>`
};
const serve = type => render[type](model[type]).parentNode.toString();
addEventListener('fetch', event => {
event.respondWith(new Response(
serve('index'),
{
status: 200,
statusText: 'OK',
headers: {'content-type': 'text/html;charset=utf-8'}
}
))
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment