Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}, (err) => {
if (err) {
if (err.statusCode && err.statusCode === 404) {
// Pass through to next middleware
next();
} else {
next(err);
}
return;
}
debug('Exposing context state');
const exposed = 'window.App=' + serialize(app.dehydrate(context)) + ';';
debug('Rendering Application component into html');
const markup = ReactDOM.renderToString(createElementWithContext(context));
const htmlElement = React.createElement(HtmlComponent, {
clientFile: env === 'production' ? 'main.min.js' : 'main.js',
context: context.getComponentContext(),
state: exposed,
markup: markup
});
const html = ReactDOM.renderToStaticMarkup(htmlElement);
debug('Sending markup');
res.type('html');
res.write('' + html);
res.end();
});
});
.then(() => {
let contextEl = FluxibleReact.createElementWithContext(context);
let container = document.getElementById('main');
ReactDOM.render(contextEl, container);
})
.catch((error) => {
}, (err) => {
if (err) {
if (err.statusCode && err.statusCode === 404) {
next();
} else {
next(err);
}
return;
}
debug('Exposing context state');
const exposed = 'window.App=' + serialize(app.dehydrate(context)) + ';';
debug('Rendering Application component into html');
const markup = ReactDOM.renderToString(createElementWithContext(context));
const htmlElement = React.createElement(HtmlComponent, {
//clientFile: env === 'production' ? 'main.min.js' : 'main.js',
//use main.js for both dev and prod modes
clientFile: 'main.js',
addAssets: (env === 'production'),
context: context.getComponentContext(),
state: exposed,
markup: markup
});
const html = ReactDOM.renderToStaticMarkup(htmlElement);
debug('Sending markup');
res.type('html');
res.write('' + html);
res.end();
});
function renderApp(res, context) {
const appElement = createElementWithContext(context);
const renderedApp = renderToString(appElement);
const exposed = 'window.App=' + serialize(app.dehydrate(context)) + ';';
const doctype = '';
const componentContext = context.getComponentContext();
const html = renderToStaticMarkup(htmlComponent({
assets: assets,
context: componentContext,
state: exposed,
markup: renderedApp
}));
res.send(doctype + html);
}
function renderPage(req, res, context) {
debug('Exposing context state');
var exposed = 'window.App=' + serialize(app.dehydrate(context)) + ';';
var mainMarkup;
if ('0' === req.query.render) {
mainMarkup = '';
} else {
mainMarkup = ReactDOM.renderToString(createElement(context));
}
debug('Rendering Application component into html');
var html = ReactDOM.renderToStaticMarkup(React.createElement(HtmlComponent, {
state: exposed,
markup: mainMarkup
}));
debug('Sending markup');
res.send(html);
}
.then(() => {
let container = document.getElementById('main');
ReactDOM.render(FluxibleReact.createElementWithContext(context), container);
});
function renderApp (res, context, app, props) {
var state;
props.mainScript = settings.web.assets.mainScript();
props.images = settings.web.images;
props.trackingSnippet = config.analytics.snippet;
debug('Creating app state');
state = app.dehydrate(context);
state.analytics = config.analytics.globalRef;
props.state = 'window.App=' + serialize(state) + ';';
debug('Rendering app component into html');
props.markup = ReactDOM.renderToString(createElement(context));
props.context = context.getComponentContext();
res.send('' +
ReactDOM.renderToStaticMarkup(HtmlComponent(props))
);
}
app.rehydrate(dehydratedState, function(error, context) {
if (error) {
throw error;
}
window.context = context;
let mountNode = document.getElementById('app');
debug('React Rendering');
React.render(createElementWithContext(context), mountNode, function() {
debug('React Rendered');
});
});