Merge branch 'master' into 'gray'
Master See merge request !64
Showing
6 changed files
with
45 additions
and
36 deletions
@@ -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'; |
@@ -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 | - } catch (err) { | ||
123 | - logger.error(err); | ||
124 | - } | ||
125 | 122 | ||
126 | // listener | 123 | // listener |
127 | app.listen(config.port, function() { | 124 | app.listen(config.port, function() { |
128 | logger.info(`worker is started at ${config.port}`); | 125 | logger.info(`worker is started at ${config.port}`); |
129 | }); | 126 | }); |
127 | + } catch (err) { | ||
128 | + if (err.code === 9999) { | ||
129 | + logger.error(err); | ||
130 | + process.abort(); | ||
131 | + } | ||
132 | + logger.error(err); | ||
133 | + } | ||
134 | + | ||
130 | }; | 135 | }; |
@@ -58,9 +58,15 @@ const render = (req, res, next) => { | @@ -58,9 +58,15 @@ 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([ | 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([ | ||
64 | rp(`http://cdn.yoho.cn/yohoblk-wap/bundle/yoho-ssr-server-${pkg.version}.json`, {json: true}), | 70 | 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}), | 71 | rp(`http://cdn.yoho.cn/yohoblk-wap/bundle/yoho-ssr-client-${pkg.version}.json`, {json: true}), |
66 | ]).then(results => { | 72 | ]).then(results => { |
@@ -70,6 +76,8 @@ if (!isDev) { | @@ -70,6 +76,8 @@ if (!isDev) { | ||
70 | template, | 76 | template, |
71 | clientManifest: results[1] | 77 | clientManifest: results[1] |
72 | }); | 78 | }); |
79 | + }).catch(() => { | ||
80 | + return loadBundle(errorCount + 1); | ||
73 | }); | 81 | }); |
74 | 82 | ||
75 | // const serverBundle = require(`../../public/dist/yohoblk-wap/bundle/yoho-ssr-server-${pkg.version}.json`); | 83 | // const serverBundle = require(`../../public/dist/yohoblk-wap/bundle/yoho-ssr-server-${pkg.version}.json`); |
@@ -80,7 +88,9 @@ if (!isDev) { | @@ -80,7 +88,9 @@ if (!isDev) { | ||
80 | // template, | 88 | // template, |
81 | // clientManifest | 89 | // clientManifest |
82 | // }); | 90 | // }); |
83 | -} | 91 | + } |
92 | +}; | ||
93 | + | ||
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", |
@@ -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" |
-
Please register or login to post a comment