express反向代理

2018-07-24  本文已影响0人  小米bb
/**
 * 反向代理
 */
const express = require('express');

const router = express.Router();
const proxy = require('http-proxy-middleware');

// 代理服务
router.use('/', proxy({
  target: 'http://120.79.88.200:8761',
  changeOrigin: true,
  onProxyReq(proxyReq, req) {
    if (req.user && req.user.accessToken) { proxyReq.setHeader('Authorization', `Bearer ${req.user.accessToken}`); }
  },
  ws: true,
}));

module.exports = router;
上一篇下一篇

猜你喜欢

热点阅读