Skip to content

Instantly share code, notes, and snippets.

@nickbalestra
Created October 10, 2017 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickbalestra/d03e0dc8d5ca49838e31def8f63b6824 to your computer and use it in GitHub Desktop.
Save nickbalestra/d03e0dc8d5ca49838e31def8f63b6824 to your computer and use it in GitHub Desktop.
const http = require('http');
const url = require('url');
const querystring = require('querystring');
const oc = require('oc');
const client = new oc.Client({
registries: {
clientRendering: 'http://localhost:3000/',
serverRendering: 'http://localhost:3000/'
}
});
http.createServer(function (req, res) {
const query = querystring.parse(url.parse(req.url).query);
const components = [
{ name: 'oc-client' },
{ name: 'react-app', parameters: query }
];
const options = {
container: false,
timeout: 10
};
client.renderComponents(components, options, function(err, html){
res.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
const htmlResp = `<!DOCTYPE html>
<html>
<head>
<title>A page</title>
</head>
<body>
${html[1]}
${html[0]}
</body>
</html>
`
res.end(htmlResp);
});
}).listen(4000, function(){
console.log('listening on http://localhost:4000/');
// open => 'http://localhost:4000?name=Frank'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment