Authored by 姜枫

fix page cache middleware bug on windows

@@ -16,8 +16,8 @@ module.exports = { @@ -16,8 +16,8 @@ module.exports = {
16 siteUrl: '//m.yohobuy.com', 16 siteUrl: '//m.yohobuy.com',
17 assetUrl: '//localhost:5001', 17 assetUrl: '//localhost:5001',
18 domains: { 18 domains: {
19 - api: 'http://api-test3.yohops.com:9999/',  
20 - service: 'http://service-test3.yohops.com:9999/', 19 + api: 'http://api.yoho.cn/',
  20 + service: 'http://service.yoho.cn/',
21 liveApi: 'http://testapi.live.yohops.com:9999/', 21 liveApi: 'http://testapi.live.yohops.com:9999/',
22 singleApi: 'http://api-test3.yohops.com:9999/' 22 singleApi: 'http://api-test3.yohops.com:9999/'
23 23
@@ -67,7 +67,7 @@ module.exports = { @@ -67,7 +67,7 @@ module.exports = {
67 port: '4444' // influxdb port 67 port: '4444' // influxdb port
68 }, 68 },
69 console: { 69 console: {
70 - level: 'debug', 70 + level: 'error',
71 colorize: 'all', 71 colorize: 'all',
72 prettyPrint: true 72 prettyPrint: true
73 } 73 }
1 1
2 'use strict'; 2 'use strict';
3 3
4 -const path = require('path');  
5 const cachePage = require('../../config/cache'); 4 const cachePage = require('../../config/cache');
6 const logger = global.yoho.logger; 5 const logger = global.yoho.logger;
  6 +const _ = require('lodash');
  7 +
  8 +function urlJoin(a, b) {
  9 + if (_.endsWith(a, '/') && _.startsWith(b, '/')) {
  10 + return a + b.substring(1, b.length);
  11 + } else if (!_.endsWith(a, '/') && !_.startsWith(b, '/')) {
  12 + return a + '/' + b;
  13 + } else {
  14 + return a + b;
  15 + }
  16 +}
7 17
8 module.exports = () => { 18 module.exports = () => {
9 return (req, res, next) => { 19 return (req, res, next) => {
@@ -11,7 +21,7 @@ module.exports = () => { @@ -11,7 +21,7 @@ module.exports = () => {
11 function onRender() { 21 function onRender() {
12 let route = req.route ? req.route.path : ''; 22 let route = req.route ? req.route.path : '';
13 let appPath = req.app.mountpath; 23 let appPath = req.app.mountpath;
14 - let key = path.join(appPath, route.toString()); // route may be a regexp 24 + let key = urlJoin(appPath, route.toString()); // route may be a regexp
15 25
16 req.app.set('etag', false); 26 req.app.set('etag', false);
17 27