...
|
...
|
@@ -58,29 +58,39 @@ const render = (req, res, next) => { |
|
|
return res.send(html);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
if (!isDev) {
|
|
|
Promise.all([
|
|
|
rp(`http://cdn.yoho.cn/yohoblk-wap/bundle/yoho-ssr-server-${pkg.version}.json`, {json: true}),
|
|
|
rp(`http://cdn.yoho.cn/yohoblk-wap/bundle/yoho-ssr-client-${pkg.version}.json`, {json: true}),
|
|
|
]).then(results => {
|
|
|
logger.warn('ssr file is loaded');
|
|
|
renderer = createBundleRenderer(results[0], {
|
|
|
runInNewContext: false,
|
|
|
template,
|
|
|
clientManifest: results[1]
|
|
|
const loadBundle = async (errorCount = 0) => {
|
|
|
if (!isDev) {
|
|
|
if (errorCount > 5) {
|
|
|
throw {
|
|
|
code: 9999,
|
|
|
message: 'ssr bundle download faild 5!'
|
|
|
};
|
|
|
}
|
|
|
await Promise.all([
|
|
|
rp(`http://cdn.yoho.cn/yohoblk-wap/bundle/yoho-ssr-server-${pkg.version}.json`, {json: true}),
|
|
|
rp(`http://cdn.yoho.cn/yohoblk-wap/bundle/yoho-ssr-client-${pkg.version}.json`, {json: true}),
|
|
|
]).then(results => {
|
|
|
logger.warn('ssr file is loaded');
|
|
|
renderer = createBundleRenderer(results[0], {
|
|
|
runInNewContext: false,
|
|
|
template,
|
|
|
clientManifest: results[1]
|
|
|
});
|
|
|
}).catch(() => {
|
|
|
return loadBundle(errorCount + 1);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
// const serverBundle = require(`../../public/dist/yohoblk-wap/bundle/yoho-ssr-server-${pkg.version}.json`);
|
|
|
// const clientManifest = require(`../../public/dist/yohoblk-wap/bundle/yoho-ssr-client-${pkg.version}.json`);
|
|
|
// const serverBundle = require(`../../public/dist/yohoblk-wap/bundle/yoho-ssr-server-${pkg.version}.json`);
|
|
|
// const clientManifest = require(`../../public/dist/yohoblk-wap/bundle/yoho-ssr-client-${pkg.version}.json`);
|
|
|
|
|
|
// renderer = createBundleRenderer(serverBundle, {
|
|
|
// runInNewContext: false,
|
|
|
// template,
|
|
|
// clientManifest
|
|
|
// });
|
|
|
}
|
|
|
};
|
|
|
|
|
|
// renderer = createBundleRenderer(serverBundle, {
|
|
|
// runInNewContext: false,
|
|
|
// template,
|
|
|
// clientManifest
|
|
|
// });
|
|
|
}
|
|
|
|
|
|
const ssrRender = isDev ? (req, res, next) => {
|
|
|
let context = getContext(req);
|
...
|
...
|
@@ -120,6 +130,7 @@ const routes = [ |
|
|
'/about'
|
|
|
];
|
|
|
|
|
|
module.exports = app => {
|
|
|
module.exports = async (app) => {
|
|
|
await loadBundle();
|
|
|
_.each(routes, r => app.get(r, ssrRender));
|
|
|
}; |
...
|
...
|
|