2019-01-24 23:49:21 +00:00
|
|
|
import { renderToString, renderToStaticMarkup } from 'react-dom/server';
|
2019-01-13 03:27:28 +00:00
|
|
|
|
2019-07-10 00:21:25 +00:00
|
|
|
import MainApp from '../client/main/App.js';
|
2019-07-25 00:55:13 +00:00
|
|
|
import MainTemplate from '../templates/MainTemplate.js';
|
|
|
|
import getScripts from '../utils/getScripts.js';
|
|
|
|
import { createElement, createHTML } from '../utils/markup.js';
|
2019-01-24 23:49:21 +00:00
|
|
|
|
|
|
|
const doctype = '<!DOCTYPE html>';
|
2019-01-24 05:27:58 +00:00
|
|
|
const globalURLs =
|
2019-01-24 05:43:52 +00:00
|
|
|
process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'staging'
|
2019-01-24 05:27:58 +00:00
|
|
|
? {
|
|
|
|
'@emotion/core': '/@emotion/core@10.0.6/dist/core.umd.min.js',
|
2019-07-25 00:55:13 +00:00
|
|
|
react: '/react@16.8.6/umd/react.production.min.js',
|
|
|
|
'react-dom': '/react-dom@16.8.6/umd/react-dom.production.min.js'
|
2019-01-24 05:27:58 +00:00
|
|
|
}
|
|
|
|
: {
|
|
|
|
'@emotion/core': '/@emotion/core@10.0.6/dist/core.umd.min.js',
|
2019-07-25 00:55:13 +00:00
|
|
|
react: '/react@16.8.6/umd/react.development.js',
|
|
|
|
'react-dom': '/react-dom@16.8.6/umd/react-dom.development.js'
|
2019-01-24 05:27:58 +00:00
|
|
|
};
|
|
|
|
|
2019-01-13 03:27:28 +00:00
|
|
|
export default function serveMainPage(req, res) {
|
2019-01-24 23:49:21 +00:00
|
|
|
const content = createHTML(renderToString(createElement(MainApp)));
|
2019-07-10 06:50:00 +00:00
|
|
|
const elements = getScripts('main', 'iife', globalURLs);
|
2019-01-24 23:49:21 +00:00
|
|
|
|
|
|
|
const html =
|
|
|
|
doctype +
|
|
|
|
renderToStaticMarkup(createElement(MainTemplate, { content, elements }));
|
2019-01-13 03:27:28 +00:00
|
|
|
|
|
|
|
res
|
|
|
|
.set({
|
|
|
|
'Cache-Tag': 'main'
|
|
|
|
})
|
|
|
|
.send(html);
|
|
|
|
}
|