Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports = module.exports = function(options, callback) {
var context = options.context || {};
var callback = callback || function(err) {
debug(err);
};
var clientScripts = options.clientScripts || [];
var component = options.component || function() {
debug('no component passed!');
};
// application data (this has the same effect as handlebars context, except for react components)
var renderedComponent = component(context);
// render the react markup to a string
ReactAsync.renderComponentToStringWithAsyncState(renderedComponent, function(err, markup, data) {
if (!markup) {
debug(util.inspect(err));
return callback('could not render markup - check server console');
}
// add doctype to markup (not possible in jsx - so it needs to be done dirty)
markup = '' + markup;
callback(err, options.staticPage ? markup : ReactAsync.injectIntoMarkup(markup, data, clientScripts));
});
};
app.get('*',function(req,res){
var path = url.parse(req.url).pathname;
ReactAsync.renderComponentToStringWithAsyncState(App({path:path}),function(err, markup) {
res.send(''+markup);
});
});
function renderRouteComponent(req, res, next) {
var path = url.parse(req.url).pathname;
var app = ReactApp({path: path});
ReactAsync.renderComponentToStringWithAsyncState(app, function(err, markup, data) {
if (err) return next(err);
res.send(ReactAsync.injectIntoMarkup(markup, data, ['/js/bundle.js']));
});
}
function renderApp(req, res, next) {
var path = url.parse(req.url).pathname;
var app = App({path: path});
ReactAsync.renderComponentToStringWithAsyncState(app, function(err, markup) {
if (err) {
return next(err);
}
res.send(markup);
});
}
router.get('*',function(req,res){
var path = url.parse(req.url).pathname;
ReactAsync.renderComponentToStringWithAsyncState(App({path:path}),function(err, markup) {
res.send(''+markup);
});
});
function renderApp(req, res, next) {
var path = url.parse(req.url).pathname;
var app = App({path: path});
ReactAsync.renderComponentToStringWithAsyncState(app, function(err, markup) {
if (err) {
return next(err);
}
res.send('\n' + markup);
});
}