main.js 577 Bytes
const router = require('express').Router();
const rp = require('request-promise');
const env = global.env;
const pageCache = {};

const mainProxy = (req, res) => {
  res.header('x-version', env.version);
  res.header('cache-control', 'no-store');
  if (pageCache[env.version]) {
    return res.send(pageCache[env.version]);
  }
  return rp.get(`http://cdn.yoho.cn/yoho-shop-manage/${env.version}/index.html`).then(body => {
    pageCache[env.version] = body;
    res.send(body);
  });
};

router.get('/', mainProxy);
router.get(/\.html$/, mainProxy);

module.exports = router;