]> Untitled Git - lemmy-ui.git/commitdiff
Inferno helmet SSR.
authorDessalines <tyhou13@gmx.com>
Fri, 11 Sep 2020 04:03:01 +0000 (23:03 -0500)
committerDessalines <tyhou13@gmx.com>
Fri, 11 Sep 2020 04:03:01 +0000 (23:03 -0500)
src/server/index.tsx
webpack.config.js

index 26771e2c61d22bfbbac6134480306ade4f6c248e..ce89a7fa8e9915ff635de5d48f6a00f53489f82f 100644 (file)
@@ -12,6 +12,7 @@ import IsomorphicCookie from 'isomorphic-cookie';
 import { lemmyHttp, setAuth } from '../shared/utils';
 import { GetSiteForm, GetSiteResponse } from 'lemmy-js-client';
 import process from 'process';
+import { Helmet } from 'inferno-helmet';
 
 const server = express();
 const port = 1234;
@@ -65,12 +66,19 @@ server.get('/*', async (req, res) => {
     return res.redirect(context.url);
   }
 
+  const root = renderToString(wrapper);
+  const helmet = Helmet.renderStatic();
+
   res.send(`
            <!DOCTYPE html>
-           <html lang="en">
+           <html ${helmet.htmlAttributes.toString()} lang="en">
            <head>
            <script>window.isoData = ${serialize(isoData)}</script>      
 
+           ${helmet.title.toString()}
+           ${helmet.meta.toString()}
+           ${helmet.link.toString()}
+
            <!-- Required meta tags -->
            <meta name="Description" content="Lemmy">
            <meta charset="utf-8">
@@ -89,14 +97,14 @@ server.get('/*', async (req, res) => {
            <link rel="stylesheet" type="text/css" href="/static/assets/css/themes/darkly.min.css" id="default-dark" media="(prefers-color-scheme: no-preference), (prefers-color-scheme: dark)" />
            </head>
 
-           <body>
+           <body ${helmet.bodyAttributes.toString()}>
              <noscript>
                <nav class="navbar fixed-bottom navbar-light bg-light">
                 Javascript is disabled. Actions will not work.
                </nav>
              </noscript>
             
-             <div id='root'>${renderToString(wrapper)}</div>
+             <div id='root'>${root}</div>
              <script src='/static/js/client.js'></script>
            </body>
          </html>
index e36f8190d303b57cba1b36f681fc8b9e8f509a9b..74b181b3005c4e827537efabdffe3c0527127531 100644 (file)
@@ -49,7 +49,7 @@ module.exports = function (env, _) {
   // server-specific configuration
   if (env.platform === 'server') {
     base.target = 'node';
-    base.externals = [nodeExternals()];
+    base.externals = [nodeExternals(), 'inferno-helmet'];
   }
   // client-specific configurations
   if (env.platform === 'client') {