Created
October 10, 2017 15:54
-
-
Save nickbalestra/d03e0dc8d5ca49838e31def8f63b6824 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
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