var html ='<!DOCTYPE html>\n'+
'<html>\n'+
' <head>\n'+
' <meta charset="utf-8" />\n'+
' <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">\n'+
' <title>foobunny rulez!</title>\n'+
' <link rel=\'stylesheet\' href=\'/styles/app.css\' />\n'+
' <script src="http://127.0.0.1:6789/scripts/lib/require.js"></script>\n'+
' </head>\n'+
' <body> \n'+
' <script> \n'+
' document.write("test");\n'+
' require([\'/scripts/config.js\']);\n'+
' require([\'/scripts/main.js\']);\n'+
' </script>\n'+
' </body>\n'+
'</html>';
var jsdom = require("jsdom");
jsdom.defaultDocumentFeatures = {
FetchExternalResources : ['script'],
ProcessExternalResources : ['script'],
MutationEvents : '2.0',
QuerySelector : false
}
var window = jsdom.jsdom(html, null, {
features: {
FetchExternalResources: ["script"],
ProcessExternalResources: ["script"]
}
}).createWindow();
window.addEventListener('load', function(){
setTimeout(function(){
res.send('<html>'+window.document.getElementsByTagName('html')[0].innerHTML)+'</html>';
}, 5000);
});
I have this small bit of code and require does end up adding the script tags to the head
(it adds <script type="text/javascript" charset="utf-8" data-requirecontext="_" data-requiremodule="/scripts/config.js" src="/scripts/config.js"></script>
<script type="text/javascript" charset="utf-8" data-requirecontext="_" data-requiremodule="/scripts/main.js" src="/scripts/main.js"></script>)
But the problem is that it doesn't seem to run any of the code within those scripts (which include more require statements). When the page loads everything runs perfectly, but I am trying to do server side rendering.
Should I be using absolute paths? I tried using http://127.0.0.1:6789/scripts/main.js and same for everything else but it doesn't seem to be working. What could be wrong?