Authored by 陈峰

Merge branch 'master' into 'gray'

Master



See merge request !64
@@ -35,7 +35,7 @@ yohoLib.global(config); @@ -35,7 +35,7 @@ yohoLib.global(config);
35 global.utils = path.resolve('./utils'); 35 global.utils = path.resolve('./utils');
36 global.doraemon = path.resolve('./doraemon'); 36 global.doraemon = path.resolve('./doraemon');
37 37
38 -exports.createApp = (app) => { 38 +exports.createApp = async (app) => {
39 // 向模板注入变量 39 // 向模板注入变量
40 app.locals.devEnv = app.get('env') === 'development'; 40 app.locals.devEnv = app.get('env') === 'development';
41 app.locals.proEnv = app.get('env') === 'production'; 41 app.locals.proEnv = app.get('env') === 'production';
@@ -49,7 +49,7 @@ exports.createApp = (app) => { @@ -49,7 +49,7 @@ exports.createApp = (app) => {
49 app.use(devtools()); 49 app.use(devtools());
50 } 50 }
51 51
52 - 52 +
53 app.use(global.yoho.hbs({ 53 app.use(global.yoho.hbs({
54 extname: '.hbs', 54 extname: '.hbs',
55 defaultLayout: 'layout', 55 defaultLayout: 'layout',
@@ -112,19 +112,24 @@ exports.createApp = (app) => { @@ -112,19 +112,24 @@ exports.createApp = (app) => {
112 app.use(ssrApi()); 112 app.use(ssrApi());
113 app.use(layoutTools()); 113 app.use(layoutTools());
114 114
115 - require('./doraemon/middleware/ssr')(app); 115 + await require('./doraemon/middleware/ssr')(app);
116 require('./dispatch')(app); 116 require('./dispatch')(app);
117 117
118 app.all('*', errorHanlder.notFound()); // 404 118 app.all('*', errorHanlder.notFound()); // 404
119 119
120 // YOHO 后置中间件 120 // YOHO 后置中间件
121 app.use(errorHanlder.serverError()); 121 app.use(errorHanlder.serverError());
  122 +
  123 + // listener
  124 + app.listen(config.port, function() {
  125 + logger.info(`worker is started at ${config.port}`);
  126 + });
122 } catch (err) { 127 } catch (err) {
  128 + if (err.code === 9999) {
  129 + logger.error(err);
  130 + process.abort();
  131 + }
123 logger.error(err); 132 logger.error(err);
124 } 133 }
125 134
126 - // listener  
127 - app.listen(config.port, function() {  
128 - logger.info(`worker is started at ${config.port}`);  
129 - });  
130 }; 135 };
@@ -58,29 +58,39 @@ const render = (req, res, next) => { @@ -58,29 +58,39 @@ const render = (req, res, next) => {
58 return res.send(html); 58 return res.send(html);
59 }); 59 });
60 }; 60 };
61 -  
62 -if (!isDev) {  
63 - Promise.all([  
64 - rp(`http://cdn.yoho.cn/yohoblk-wap/bundle/yoho-ssr-server-${pkg.version}.json`, {json: true}),  
65 - rp(`http://cdn.yoho.cn/yohoblk-wap/bundle/yoho-ssr-client-${pkg.version}.json`, {json: true}),  
66 - ]).then(results => {  
67 - logger.warn('ssr file is loaded');  
68 - renderer = createBundleRenderer(results[0], {  
69 - runInNewContext: false,  
70 - template,  
71 - clientManifest: results[1] 61 +const loadBundle = async (errorCount = 0) => {
  62 + if (!isDev) {
  63 + if (errorCount > 5) {
  64 + throw {
  65 + code: 9999,
  66 + message: 'ssr bundle download faild 5!'
  67 + };
  68 + }
  69 + await Promise.all([
  70 + rp(`http://cdn.yoho.cn/yohoblk-wap/bundle/yoho-ssr-server-${pkg.version}.json`, {json: true}),
  71 + rp(`http://cdn.yoho.cn/yohoblk-wap/bundle/yoho-ssr-client-${pkg.version}.json`, {json: true}),
  72 + ]).then(results => {
  73 + logger.warn('ssr file is loaded');
  74 + renderer = createBundleRenderer(results[0], {
  75 + runInNewContext: false,
  76 + template,
  77 + clientManifest: results[1]
  78 + });
  79 + }).catch(() => {
  80 + return loadBundle(errorCount + 1);
72 }); 81 });
73 - });  
74 82
75 - // const serverBundle = require(`../../public/dist/yohoblk-wap/bundle/yoho-ssr-server-${pkg.version}.json`);  
76 - // const clientManifest = require(`../../public/dist/yohoblk-wap/bundle/yoho-ssr-client-${pkg.version}.json`); 83 + // const serverBundle = require(`../../public/dist/yohoblk-wap/bundle/yoho-ssr-server-${pkg.version}.json`);
  84 + // const clientManifest = require(`../../public/dist/yohoblk-wap/bundle/yoho-ssr-client-${pkg.version}.json`);
  85 +
  86 + // renderer = createBundleRenderer(serverBundle, {
  87 + // runInNewContext: false,
  88 + // template,
  89 + // clientManifest
  90 + // });
  91 + }
  92 +};
77 93
78 - // renderer = createBundleRenderer(serverBundle, {  
79 - // runInNewContext: false,  
80 - // template,  
81 - // clientManifest  
82 - // });  
83 -}  
84 94
85 const ssrRender = isDev ? (req, res, next) => { 95 const ssrRender = isDev ? (req, res, next) => {
86 let context = getContext(req); 96 let context = getContext(req);
@@ -120,6 +130,7 @@ const routes = [ @@ -120,6 +130,7 @@ const routes = [
120 '/about' 130 '/about'
121 ]; 131 ];
122 132
123 -module.exports = app => { 133 +module.exports = async (app) => {
  134 + await loadBundle();
124 _.each(routes, r => app.get(r, ssrRender)); 135 _.each(routes, r => app.get(r, ssrRender));
125 }; 136 };
1 { 1 {
2 "name": "yohoblk-wap", 2 "name": "yohoblk-wap",
3 - "version": "92.0.22", 3 + "version": "2.0.28",
4 "private": true, 4 "private": true,
5 "description": "A New Yohobuy Project With Express", 5 "description": "A New Yohobuy Project With Express",
6 "repository": { 6 "repository": {
@@ -55,6 +55,20 @@ @@ -55,6 +55,20 @@
55 "yoho-md5": "^2.0.0", 55 "yoho-md5": "^2.0.0",
56 "yoho-node-lib": "=0.5.21", 56 "yoho-node-lib": "=0.5.21",
57 "yoho-qs": "1.0.1", 57 "yoho-qs": "1.0.1",
  58 + "vue": "^2.5.13",
  59 + "vue-server-renderer": "^2.5.13",
  60 + "vue-awesome-swiper": "^3.0.6",
  61 + "vue-hot-reload-api": "^1.2.0",
  62 + "vue-html-loader": "^1.2.4",
  63 + "vue-infinite-scroll": "^2.0.1",
  64 + "vue-lazyload": "^1.0.6",
  65 + "vue-loader": "^13.7.0",
  66 + "vue-router": "^3.0.1",
  67 + "vue-style-loader": "^3.0.3",
  68 + "vue-swipe": "^2.0.3",
  69 + "vue-template-compiler": "^2.5.13",
  70 + "vue-touch": "2.0.0-beta.3",
  71 + "vuex": "^3.0.1",
58 "yoho-store": "^1.3.20" 72 "yoho-store": "^1.3.20"
59 }, 73 },
60 "devDependencies": { 74 "devDependencies": {
@@ -114,20 +128,6 @@ @@ -114,20 +128,6 @@
114 "stylelint-processor-html": "^1.0.0", 128 "stylelint-processor-html": "^1.0.0",
115 "uglifyjs-webpack-plugin": "^0.4.6", 129 "uglifyjs-webpack-plugin": "^0.4.6",
116 "url-loader": "^0.5.9", 130 "url-loader": "^0.5.9",
117 - "vue": "^2.5.13",  
118 - "vue-awesome-swiper": "^3.0.6",  
119 - "vue-hot-reload-api": "^1.2.0",  
120 - "vue-html-loader": "^1.2.4",  
121 - "vue-infinite-scroll": "^2.0.1",  
122 - "vue-lazyload": "^1.0.6",  
123 - "vue-loader": "^13.7.0",  
124 - "vue-router": "^3.0.1",  
125 - "vue-server-renderer": "^2.5.13",  
126 - "vue-style-loader": "^3.0.3",  
127 - "vue-swipe": "^2.0.3",  
128 - "vue-template-compiler": "^2.5.13",  
129 - "vue-touch": "2.0.0-beta.3",  
130 - "vuex": "^3.0.1",  
131 "webpack": "3.3", 131 "webpack": "3.3",
132 "webpack-bundle-analyzer": "^2.9.1", 132 "webpack-bundle-analyzer": "^2.9.1",
133 "webpack-dashboard": "^0.1.8", 133 "webpack-dashboard": "^0.1.8",
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 { 3 {
4 "name": "yohoblk-wap", 4 "name": "yohoblk-wap",
5 "script": "app.js", 5 "script": "app.js",
6 - "instances": "max", 6 + "instances": "4",
7 "exec_mode": "cluster", 7 "exec_mode": "cluster",
8 "merge_logs": true, 8 "merge_logs": true,
9 "log_date_format": "YYYY-MM-DD HH:mm:ss Z", 9 "log_date_format": "YYYY-MM-DD HH:mm:ss Z",
@@ -89,7 +89,7 @@ @@ -89,7 +89,7 @@
89 productList: [], 89 productList: [],
90 inSearching: false, 90 inSearching: false,
91 enableOrder: false, 91 enableOrder: false,
92 - order: '', 92 + order: 's_t_desc',
93 cartCount: 0 93 cartCount: 0
94 }; 94 };
95 }, 95 },
@@ -8908,7 +8908,7 @@ vue-router@^3.0.1: @@ -8908,7 +8908,7 @@ vue-router@^3.0.1:
8908 8908
8909 vue-server-renderer@^2.5.13: 8909 vue-server-renderer@^2.5.13:
8910 version "2.5.13" 8910 version "2.5.13"
8911 - resolved "https://registry.yarnpkg.com/vue-server-renderer/-/vue-server-renderer-2.5.13.tgz#6a0d421a0fd3e2b7357b59495d744b7e9279d68e" 8911 + resolved "http://npm.yohops.com/vue-server-renderer/-/vue-server-renderer-2.5.13.tgz#6a0d421a0fd3e2b7357b59495d744b7e9279d68e"
8912 dependencies: 8912 dependencies:
8913 chalk "^1.1.3" 8913 chalk "^1.1.3"
8914 hash-sum "^1.0.2" 8914 hash-sum "^1.0.2"
@@ -8919,20 +8919,13 @@ vue-server-renderer@^2.5.13: @@ -8919,20 +8919,13 @@ vue-server-renderer@^2.5.13:
8919 serialize-javascript "^1.3.0" 8919 serialize-javascript "^1.3.0"
8920 source-map "0.5.6" 8920 source-map "0.5.6"
8921 8921
8922 -vue-style-loader@^3.0.0: 8922 +vue-style-loader@^3.0.0, vue-style-loader@^3.0.3:
8923 version "3.0.3" 8923 version "3.0.3"
8924 resolved "http://npm.yoho.cn/vue-style-loader/-/vue-style-loader-3.0.3.tgz#623658f81506aef9d121cdc113a4f5c9cac32df7" 8924 resolved "http://npm.yoho.cn/vue-style-loader/-/vue-style-loader-3.0.3.tgz#623658f81506aef9d121cdc113a4f5c9cac32df7"
8925 dependencies: 8925 dependencies:
8926 hash-sum "^1.0.2" 8926 hash-sum "^1.0.2"
8927 loader-utils "^1.0.2" 8927 loader-utils "^1.0.2"
8928 8928
8929 -vue-style-loader@^3.0.3:  
8930 - version "3.0.3"  
8931 - resolved "https://registry.yarnpkg.com/vue-style-loader/-/vue-style-loader-3.0.3.tgz#623658f81506aef9d121cdc113a4f5c9cac32df7"  
8932 - dependencies:  
8933 - hash-sum "^1.0.2"  
8934 - loader-utils "^1.0.2"  
8935 -  
8936 vue-swipe@^0.2.7: 8929 vue-swipe@^0.2.7:
8937 version "0.2.7" 8930 version "0.2.7"
8938 resolved "http://npm.yoho.cn/vue-swipe/-/vue-swipe-0.2.7.tgz#4c23ee982953a2c7e96dace55b1fafde518ab719" 8931 resolved "http://npm.yoho.cn/vue-swipe/-/vue-swipe-0.2.7.tgz#4c23ee982953a2c7e96dace55b1fafde518ab719"