Authored by 陈峰

Merge branch 'master' into 'gray'

Master



See merge request !64
... ... @@ -35,7 +35,7 @@ yohoLib.global(config);
global.utils = path.resolve('./utils');
global.doraemon = path.resolve('./doraemon');
exports.createApp = (app) => {
exports.createApp = async (app) => {
// 向模板注入变量
app.locals.devEnv = app.get('env') === 'development';
app.locals.proEnv = app.get('env') === 'production';
... ... @@ -49,7 +49,7 @@ exports.createApp = (app) => {
app.use(devtools());
}
app.use(global.yoho.hbs({
extname: '.hbs',
defaultLayout: 'layout',
... ... @@ -112,19 +112,24 @@ exports.createApp = (app) => {
app.use(ssrApi());
app.use(layoutTools());
require('./doraemon/middleware/ssr')(app);
await require('./doraemon/middleware/ssr')(app);
require('./dispatch')(app);
app.all('*', errorHanlder.notFound()); // 404
// YOHO 后置中间件
app.use(errorHanlder.serverError());
// listener
app.listen(config.port, function() {
logger.info(`worker is started at ${config.port}`);
});
} catch (err) {
if (err.code === 9999) {
logger.error(err);
process.abort();
}
logger.error(err);
}
// listener
app.listen(config.port, function() {
logger.info(`worker is started at ${config.port}`);
});
};
... ...
... ... @@ -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));
};
... ...
{
"name": "yohoblk-wap",
"version": "92.0.22",
"version": "2.0.28",
"private": true,
"description": "A New Yohobuy Project With Express",
"repository": {
... ... @@ -55,6 +55,20 @@
"yoho-md5": "^2.0.0",
"yoho-node-lib": "=0.5.21",
"yoho-qs": "1.0.1",
"vue": "^2.5.13",
"vue-server-renderer": "^2.5.13",
"vue-awesome-swiper": "^3.0.6",
"vue-hot-reload-api": "^1.2.0",
"vue-html-loader": "^1.2.4",
"vue-infinite-scroll": "^2.0.1",
"vue-lazyload": "^1.0.6",
"vue-loader": "^13.7.0",
"vue-router": "^3.0.1",
"vue-style-loader": "^3.0.3",
"vue-swipe": "^2.0.3",
"vue-template-compiler": "^2.5.13",
"vue-touch": "2.0.0-beta.3",
"vuex": "^3.0.1",
"yoho-store": "^1.3.20"
},
"devDependencies": {
... ... @@ -114,20 +128,6 @@
"stylelint-processor-html": "^1.0.0",
"uglifyjs-webpack-plugin": "^0.4.6",
"url-loader": "^0.5.9",
"vue": "^2.5.13",
"vue-awesome-swiper": "^3.0.6",
"vue-hot-reload-api": "^1.2.0",
"vue-html-loader": "^1.2.4",
"vue-infinite-scroll": "^2.0.1",
"vue-lazyload": "^1.0.6",
"vue-loader": "^13.7.0",
"vue-router": "^3.0.1",
"vue-server-renderer": "^2.5.13",
"vue-style-loader": "^3.0.3",
"vue-swipe": "^2.0.3",
"vue-template-compiler": "^2.5.13",
"vue-touch": "2.0.0-beta.3",
"vuex": "^3.0.1",
"webpack": "3.3",
"webpack-bundle-analyzer": "^2.9.1",
"webpack-dashboard": "^0.1.8",
... ...
... ... @@ -3,7 +3,7 @@
{
"name": "yohoblk-wap",
"script": "app.js",
"instances": "max",
"instances": "4",
"exec_mode": "cluster",
"merge_logs": true,
"log_date_format": "YYYY-MM-DD HH:mm:ss Z",
... ...
... ... @@ -89,7 +89,7 @@
productList: [],
inSearching: false,
enableOrder: false,
order: '',
order: 's_t_desc',
cartCount: 0
};
},
... ...
... ... @@ -8908,7 +8908,7 @@ vue-router@^3.0.1:
vue-server-renderer@^2.5.13:
version "2.5.13"
resolved "https://registry.yarnpkg.com/vue-server-renderer/-/vue-server-renderer-2.5.13.tgz#6a0d421a0fd3e2b7357b59495d744b7e9279d68e"
resolved "http://npm.yohops.com/vue-server-renderer/-/vue-server-renderer-2.5.13.tgz#6a0d421a0fd3e2b7357b59495d744b7e9279d68e"
dependencies:
chalk "^1.1.3"
hash-sum "^1.0.2"
... ... @@ -8919,20 +8919,13 @@ vue-server-renderer@^2.5.13:
serialize-javascript "^1.3.0"
source-map "0.5.6"
vue-style-loader@^3.0.0:
vue-style-loader@^3.0.0, vue-style-loader@^3.0.3:
version "3.0.3"
resolved "http://npm.yoho.cn/vue-style-loader/-/vue-style-loader-3.0.3.tgz#623658f81506aef9d121cdc113a4f5c9cac32df7"
dependencies:
hash-sum "^1.0.2"
loader-utils "^1.0.2"
vue-style-loader@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/vue-style-loader/-/vue-style-loader-3.0.3.tgz#623658f81506aef9d121cdc113a4f5c9cac32df7"
dependencies:
hash-sum "^1.0.2"
loader-utils "^1.0.2"
vue-swipe@^0.2.7:
version "0.2.7"
resolved "http://npm.yoho.cn/vue-swipe/-/vue-swipe-0.2.7.tgz#4c23ee982953a2c7e96dace55b1fafde518ab719"
... ...