Authored by 陈峰

bug:性能问题,不要每次都从cdn获取html文件

@@ -57,8 +57,12 @@ const middleware = require('./middleware'); @@ -57,8 +57,12 @@ const middleware = require('./middleware');
57 const controllers = require('./controllers'); 57 const controllers = require('./controllers');
58 58
59 app.use('/crm/common/ok.jsp', (req, res) => { 59 app.use('/crm/common/ok.jsp', (req, res) => {
60 - res.status(204).end(); 60 + res.status(200).end();
61 }); 61 });
  62 +app.head('*', (req, res) => {
  63 + res.status(200).end();
  64 +});
  65 +
62 66
63 try { 67 try {
64 app.use(middleware.main); 68 app.use(middleware.main);
@@ -2,11 +2,16 @@ const Express = require('express'); @@ -2,11 +2,16 @@ const Express = require('express');
2 let router = Express.Router(); // eslint-disable-line 2 let router = Express.Router(); // eslint-disable-line
3 const rp = require('request-promise'); 3 const rp = require('request-promise');
4 const env = global.env; 4 const env = global.env;
  5 +const pageCache = {};
5 6
6 let mainProxy = (req, res) => { 7 let mainProxy = (req, res) => {
7 res.header('x-version', env.version); 8 res.header('x-version', env.version);
8 res.header('cache-control', 'no-store'); 9 res.header('cache-control', 'no-store');
9 - rp.get(`http://cdn.yoho.cn/yoho-shop-manage/${env.version}/index.html`).then(body => { 10 + if (pageCache[env.version]) {
  11 + return res.send(pageCache[env.version]);
  12 + }
  13 + return rp.get(`http://cdn.yoho.cn/yoho-shop-manage/${env.version}/index.html`).then(body => {
  14 + pageCache[env.version] = body;
10 res.send(body); 15 res.send(body);
11 }); 16 });
12 }; 17 };