Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
await getDataFromTree(element);
if (context.pageNotFound === true) {
res.status(404);
} else {
res.status(200);
}
const sheet = new ServerStyleSheet();
const html = ReactDOMServer.renderToString(sheet.collectStyles(element));
const css = sheet
.getStyleElement()
.concat(stylesheets)
.map((el, idx) => React.cloneElement(el, { key: idx }));
const helmet = Helmet.renderStatic(); // Avoid memory leak while tracking mounted instances
if (context.url) {
res.writeHead(301, { Location: context.url });
res.end();
} else {
if (__DEV__ || !assetMap) {
assetMap = JSON.parse(fs.readFileSync(path.join(spinConfig.frontendBuildDir, 'web', 'assets.json')));
}
const apolloState = Object.assign({}, cache.extract());
const token = req.universalCookies.get('x-token') ? req.universalCookies.get('x-token') : null;
const refreshToken = req.universalCookies.get('x-refresh-token')
? req.universalCookies.get('x-refresh-token')
: null;
exports = module.exports = (request, response) => {
// handle redirect if we aren't logged in
if(request.session.loggedIn) {
response.redirect(301, '/');
return;
}
// generate a string that we will render to the page
const html = renderToString();
// get values for head: title, meta tags
const head = Helmet.renderStatic();
// render the page, and send it to the client
response.send(renderLayout(head, html, 'login', {}, !!(request.user && request.user.isAdmin)))
};
export const Html = ({ assets, component, store }) => {
const content = ReactDOM.renderToString(component);
const head = Helmet.rewind();
// Workaround for testing
// Otherwise we get TypeError: _reactHelmet2.default.renderStatic is not a function
const helmet =
process.env.NODE_ENV === 'production' ? Helmet.renderStatic() : null;
const bodyAttrs = helmet && helmet.bodyAttributes.toComponent();
return (
{head.base.toComponent()}
{head.title.toComponent()}
{head.meta.toComponent()}
{head.link.toComponent()}
{head.script.toComponent()}
{/* styles (will be present only in production with webpack extract text plugin) */}
{Object.keys(assets.styles).map(style => (
const client = createClient(req);
const app = (
);
// Executes all graphql queries for the current state of application
await getDataFromTree(app);
const content = ReactDOMServer.renderToStaticMarkup(app);
const state = client.extract();
const helmet = Helmet.renderStatic();
const html = ReactDOMServer.renderToStaticMarkup(
);
res.status(200);
res.send(`${html}`);
res.end();
});
router.get("/*", (ctx: Koa.Context, next) => {
const context = {};
const { req } = ctx;
const store: Store = createStore();
try {
store.dispatch(initializeSession());
const reactDom = getRenderDom(context, req, store);
const reduxState = store.getState();
const helmetData = Helmet.renderStatic();
ctx.status = 200;
ctx.set("Content-Type", "text/html");
ctx.body = htmlTemplate(reactDom, reduxState, helmetData);
} catch (err) {
console.log(err);
next();
}
});
}).then(() => {
const componentHTML = renderToString(
{routes}
);
const head = Helmet.renderStatic();
const html = renderHTML(
componentHTML,
store.getState(),
webpackIsomorphicTools.assets(),
head,
);
return { html };
}).then(({ html }) => {
if (req.url === '/404') {
const Html = ({
styles, assets, state, content,
}) => {
const helmet = Helmet.renderStatic()
const htmlAttrs = helmet.htmlAttributes.toComponent()
const bodyAttrs = helmet.bodyAttributes.toComponent()
return (
{helmet.title.toComponent()}
{helmet.meta.toComponent()}
{helmet.link.toComponent()}
{assets.css.map(path => )}
{styles}
<main id="app">
</main>
export function renderPage(Page, assets, state = {}) {
const { html, ids, css } = extractCritical(renderToString(Page));
const helmet = Helmet.renderStatic();
return {
html,
helmet,
assets,
state,
css,
data: {
ids,
config,
},
};
}
function renderApp(ServerApp, data, req, res) {
const context = {};
const modules = [];
const markup = ReactDOMServer.renderToString(
modules.push(moduleName)}>
);
if (context.url) {
res.redirect(context.url);
} else {
const fullMarkup = indexHtml({
helmet: Helmet.renderStatic(),
serverData: data,
bundles: getBundles(stats, modules),
markup
});
res.status(200).send(fullMarkup);
}
}
static getInitialProps({ renderPage, req }) {
const { html, head, errorHtml, chunks } = renderPage();
const helmet = Helmet.renderStatic();
return { html, head, errorHtml, chunks, helmet }
}