Created
November 29, 2017 23:44
-
-
Save isaacs/cc77f3091cde7dae2fbed74e1440044d to your computer and use it in GitHub Desktop.
This file contains 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 s = require('http').createServer((q, s) => { | |
console.error(q.method, q.url) | |
switch (q.url) { | |
case '/': | |
return html(s) | |
case '/app.js': | |
return js(s) | |
default: | |
s.statusCode = 404 | |
s.setHeader('content-type', 'text/plain') | |
s.end('Not found: ' + q.url + '\n') | |
} | |
}) | |
const html = s => { | |
s.setHeader('content-type', 'text/html') | |
s.end(`<!doctype html> | |
<html> | |
<script type=module> | |
import app from './app.js' | |
app() | |
</script> | |
`) | |
} | |
const js = s => { | |
s.setHeader('content-type', 'application/javascript') | |
s.end(` | |
const el = document.createElement('h1') | |
el.innerHTML = 'blerg' | |
document.body.appendChild(el) | |
const app = () => console.log('hi from app.js') | |
export default app | |
`) | |
} | |
s.listen(8080) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment