Last active
November 20, 2018 19:03
-
-
Save WebReflection/6d4a9ee1fd4cb98e457c7705af880a39 to your computer and use it in GitHub Desktop.
hyperHTML does Cloudflare Worker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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