Last active
November 18, 2016 17:18
-
-
Save imkost/6b872729f121cb1f3067caff28f26675 to your computer and use it in GitHub Desktop.
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
// server.js | |
const http = require('http'); | |
const fs = require('fs'); | |
require('./components'); | |
const PORT = 4000; | |
const styles = fs.readFileSync('./styles.css'); | |
const components = fs.readFileSync('./components.js'); | |
http.createServer(server).listen(PORT); | |
function server(req, res) { | |
const { url } = req; | |
res.end( | |
url === '/styles.css' ? styles : | |
url === '/components.js' ? components : | |
App({ url }) // App is in global namespace (global.App) | |
); | |
} |
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
// components.js | |
function App({ url }) { | |
return ` | |
<!doctype html> | |
<html class="app"> | |
<head> | |
<meta charset="utf-8" /> | |
<link rel="stylesheet" href="/styles.css" /> | |
</head> | |
<body class="app__body"> | |
Nothing here yet, just a box: ${Box()} | |
<div class="app__scripts"> | |
<script>window.global = window;</script> | |
<script src="/components.js"></script> | |
</div> | |
</body> | |
</html> | |
` | |
} | |
function Box() { | |
return ` | |
<div class="box"></div> | |
`; | |
} | |
global.App = App; | |
global.Box = Box; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment