1
0
mirror of https://github.com/trambarhq/relaks-wordpress-example.git synced 2025-09-02 12:42:38 +02:00

Reworked code.

This commit is contained in:
Chung Leong
2019-04-19 00:06:10 +02:00
parent da30bc22a6
commit c66323e17d
58 changed files with 454 additions and 348 deletions

View File

@@ -1,6 +1,5 @@
const Bluebird = require('bluebird');
const FS = Bluebird.promisifyAll(require('fs'));
const ReactDOMServer = require('react-dom/server');
const HTTP = require('http');
const CrossFetch = require('cross-fetch');
const FrontEnd = require('./client/front-end');
@@ -26,8 +25,7 @@ async function generate(path, target) {
return CrossFetch(url, options);
};
let options = { host, path, target, fetch };
let rootNode = await FrontEnd.render(options);
let appHTML = ReactDOMServer.renderToString(rootNode);
let appHTML = await FrontEnd.render(options);
let htmlTemplate = await FS.readFileAsync(HTML_TEMPLATE, 'utf-8');
let html = htmlTemplate.replace(`<!--REACT-->`, appHTML);
if (target === 'hydrate') {
@@ -61,3 +59,4 @@ module.exports = {
prefetch,
basePath: FrontEnd.basePath
};