How to use the react-helmet.Helmet.renderStatic function in react-helmet

To help you get started, we’ve selected a few react-helmet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozilla / mozillafestival.org / server.js View on Github external
app.get(`*`, (req, res) => {
  const reactHelmet = ReactHelmet.renderStatic();
  const requestPath = req.path;

  const context = {}; // context object contains the results of the render
  const appHtml = renderToString(
    
      <main>
    
  );

  if (context.url) {
    // Somewhere a `` was rendered
    res.redirect(301, context.url);
  } else if (requestPath === "/get-fringe-events") {
    getFringeEvents(res);
  } else if (requestPath === "/get-house-events") {
    getHouseEvents(res);</main>
github atulmy / crate / code / web / src / setup / server / load-routes.js View on Github external
const initialState = store.getState()
        const context = {}

        const appHtml = renderToString(
          
            
              
            
          
        )

        if (context.url) {
          response.redirect(context.url)
        } else {
          // Get Meta header tags
          const helmet = Helmet.renderStatic()

          const styles = flushToHTML()

          const html = view(APP_URL, NODE_ENV, helmet, appHtml, styles, initialState)

          // Reset the state on server
          store.dispatch({
            type: 'RESET'
          })

          // Finally send generated HTML with initial data to the client
          return response.status(status).send(html)
        }
      })
      .catch(error =&gt; {
github alidcastano / rogue.js / packages / rogue-app / lib / server / appMiddleware.ts View on Github external
return async function handler (req, res) {
    const routerContext = { url: null }
    const serverContext = { req, res }
  
    try {
      const { markup, data, headTags, bodyTags } = await renderRoute(App, routerContext, serverContext)
       
      // redirected (see: https://reacttraining.com/react-router/web/api/StaticRouter/context-object)
      if (routerContext.url) {
        res.writeHead(302, { Location: routerContext.url })
        res.end()
        return 
      }
    
      const helmet = Helmet.renderStatic()
      const html = toHtml({ helmet, markup, data, bundleUrl, headTags, bodyTags })
  
      res.setHeader('Content-Type', 'text/html; charset=utf-8')
      res.setHeader('Content-Length', Buffer.byteLength(html))
      res.end(html, 'utf8')
    } catch (err) {
      const content = JSON.stringify({ status: err.statusCode || 500, message: err.message, name: err.name }, undefined, 2)
      res.setHeader('Content-Type', 'text/json; charset=utf-8')
      res.setHeader('Content-Length', Buffer.byteLength(content))
      res.end(content, 'utf-8')
    }
  }
}
github andreiduca / cra-ssr-code-splitting / server / middleware / renderer.js View on Github external
);

        // get the stringified state
        const reduxState = JSON.stringify(store.getState());

        // map required assets to script tags
        const extraChunks = extractAssets(manifest, modules)
            .map(c =&gt; ``);

        // get HTML headers
        const helmet = Helmet.renderStatic();

        // now inject the rendered app into our html and send it to the client
        return res.send(
            htmlData
                // write the React app
                .replace('<div id="root"></div>', `<div id="root">${html}</div>`)
                // write the string version of our state
                .replace('__REDUX_STATE__={}', `__REDUX_STATE__=${reduxState}`)
                // append the extra js assets
                .replace('', extraChunks.join('') + '')
                // write the HTML header tags
                .replace('<title></title>', helmet.title.toString() + helmet.meta.toString())
        );
    });
}
github letterpad / letterpad / src / client / server / app.tsx View on Github external
);
  try {
    const content = await renderToStringWithData(clientApp);
    const initialState = client.extract();
    return {
      head: Helmet.renderStatic(),
      html: content,
      initialData: { ...initialData, initialProps },
      apolloState: initialState,
      sheet: sheet,
    };
  } catch (error) {
    console.log("error :", error);
  }
};
github mia-js / mia-js / projects / web / src / server.jsx View on Github external
.then(data =&gt; {
                try {
                    const app = ReactDOMServer.renderToString(
                        
                            
                                
                            
                        
                    );

                    const helmet = Helmet.renderStatic();
                    const htmlAttrs = helmet.htmlAttributes.toString();
                    const bodyAttrs = helmet.bodyAttributes.toString();

                    if (context.url) {
                        return Promise.reject({
                            error: 'RedirectException',
                            message: '',
                            context
                        });
                    }

                    return '' +
                        `` +
                        '' +
                        `${helmet.title.toString()}` +
                        `${helmet.meta.toString()}` +
github pluto-net / scinapse-web-client / app / server / index.tsx View on Github external
);

  const materialUICss = sheetsRegistry.toString();
  const cssArr = Array.from(css);
  const helmet = Helmet.renderStatic();
  const currentState = store.getState();
  const stringifiedInitialReduxState = JSON.stringify(currentState);

  const html: string = await generateFullHTML({
    reactDom: renderedHTML,
    scriptPath: scriptVersion,
    helmet,
    initialState: stringifiedInitialReduxState,
    css: cssArr.join("") + materialUICss,
    version,
  });

  return {
    html,
    statusCode: routeContext.statusCode,
  };
github malj / django-parcel-ssr / ssr / scripts / react / server.js View on Github external
export default Component =&gt; ({ script, stylesheet }, props) =&gt; {
    const component = React.createElement(Component, props)
    const html = ReactDOMServer.renderToString(component)
    const helmet = Helmet.renderStatic()
    const serializedProps = encodeURIComponent(JSON.stringify(props))

    return [
        '',
        ``,
        '',
        '',
        '',
        helmet.title.toString(),
        helmet.base.toString(),
        helmet.meta.toString(),
        helmet.link.toString(),
        helmet.style.toString(),
        flushToHTML(),
        stylesheet &amp;&amp; ``,
        '',
github iran-react-community / react-community-website / src / server.jsx View on Github external
return (req, res, next) =&gt; {
        const context = {};
        const markup = ReactDOMServer.renderToString(
            
                
            
        );
        const helmet = Helmet.renderStatic();

        res.status(200).send(Template({
            markup: markup,
            helmet: helmet,
        }));
    };
}
github Tarnadas / smmdb / website / src / server / index.ts View on Github external
const d = device(req.get('user-agent'))
    let [html, preloadedState, modules] = await renderer(
      true,
      renderToString,
      null,
      req,
      await API.filterCourses(undefined, { limit: 10 }),
      await API.filterCourses64(undefined, { limit: 16 }),
      websiteStats,
      d.is('phone'),
      d.is('tablet')
    )
    const getBundles = require('react-loadable/webpack').getBundles
    const stats = require('../../build/react-loadable.json')
    const bundles = getBundles(stats, modules)
    const helmet = Helmet.renderStatic()
    const index = cheerio.load($index.html())
    index('#root').html(html)
    index('head').prepend(helmet.title.toString())
    index('head').prepend(helmet.meta.toString())
    index('head').prepend(bundles.map((bundle: any): string =&gt;
      ``
    ).join('\n'))
    index('body').prepend(``)
    res.send(index.html())
  })