mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-12-01 16:51:13 +00:00
Inferno helmet SSR.
This commit is contained in:
parent
fce2d73958
commit
d909ec8096
2 changed files with 12 additions and 4 deletions
|
@ -12,6 +12,7 @@ import IsomorphicCookie from 'isomorphic-cookie';
|
||||||
import { lemmyHttp, setAuth } from '../shared/utils';
|
import { lemmyHttp, setAuth } from '../shared/utils';
|
||||||
import { GetSiteForm, GetSiteResponse } from 'lemmy-js-client';
|
import { GetSiteForm, GetSiteResponse } from 'lemmy-js-client';
|
||||||
import process from 'process';
|
import process from 'process';
|
||||||
|
import { Helmet } from 'inferno-helmet';
|
||||||
|
|
||||||
const server = express();
|
const server = express();
|
||||||
const port = 1234;
|
const port = 1234;
|
||||||
|
@ -65,12 +66,19 @@ server.get('/*', async (req, res) => {
|
||||||
return res.redirect(context.url);
|
return res.redirect(context.url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const root = renderToString(wrapper);
|
||||||
|
const helmet = Helmet.renderStatic();
|
||||||
|
|
||||||
res.send(`
|
res.send(`
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html ${helmet.htmlAttributes.toString()} lang="en">
|
||||||
<head>
|
<head>
|
||||||
<script>window.isoData = ${serialize(isoData)}</script>
|
<script>window.isoData = ${serialize(isoData)}</script>
|
||||||
|
|
||||||
|
${helmet.title.toString()}
|
||||||
|
${helmet.meta.toString()}
|
||||||
|
${helmet.link.toString()}
|
||||||
|
|
||||||
<!-- Required meta tags -->
|
<!-- Required meta tags -->
|
||||||
<meta name="Description" content="Lemmy">
|
<meta name="Description" content="Lemmy">
|
||||||
<meta charset="utf-8">
|
<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)" />
|
<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>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body ${helmet.bodyAttributes.toString()}>
|
||||||
<noscript>
|
<noscript>
|
||||||
<nav class="navbar fixed-bottom navbar-light bg-light">
|
<nav class="navbar fixed-bottom navbar-light bg-light">
|
||||||
Javascript is disabled. Actions will not work.
|
Javascript is disabled. Actions will not work.
|
||||||
</nav>
|
</nav>
|
||||||
</noscript>
|
</noscript>
|
||||||
|
|
||||||
<div id='root'>${renderToString(wrapper)}</div>
|
<div id='root'>${root}</div>
|
||||||
<script src='/static/js/client.js'></script>
|
<script src='/static/js/client.js'></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -49,7 +49,7 @@ module.exports = function (env, _) {
|
||||||
// server-specific configuration
|
// server-specific configuration
|
||||||
if (env.platform === 'server') {
|
if (env.platform === 'server') {
|
||||||
base.target = 'node';
|
base.target = 'node';
|
||||||
base.externals = [nodeExternals()];
|
base.externals = [nodeExternals(), 'inferno-helmet'];
|
||||||
}
|
}
|
||||||
// client-specific configurations
|
// client-specific configurations
|
||||||
if (env.platform === 'client') {
|
if (env.platform === 'client') {
|
||||||
|
|
Loading…
Reference in a new issue