NODE代理,yang

const express = require('express');
const proxy = require('http-proxy-middleware');//引入代理中间件
const app = express();
app.use(express.static('webapp'));

// 测试
const host = 'http://192.168.0.232:8382';//192.168.0.232:8382/

// 本地
// const host = 'http://localhost:8091/';
// const host = 'http://192.168.6.108:80/';

// Add middleware for http proxying
//将服务器代理
const appProxy = proxy(
    '/app/', {
        target: host,
        changeOrigin: true,
        pathRewrite: {
            '^/': '/'
        }
    });
const drawProxy= proxy(
    '/draw/', {
        target: 'http://120.24.168.179:8081',
        changeOrigin: true,
        pathRewrite: {
            '^/': '/'
        }
    });
const gatewayProxy= proxy(
    '/gateway/', {
        // target: 'http://119.23.175.96:6001',
        target: 'http://192.168.0.238:6001',
        changeOrigin: true,
        pathRewrite: {
            '^/gateway': '/'
        }
    });
const thirdPartyProxy= proxy(
    '/third-party/', {
        target: 'http://192.168.0.242:8050',
        // target: 'http://m.ibaboss.com/',
        changeOrigin: true,
        pathRewrite: {
            '^/': '/'
        }
    });
app.use('/app/*', appProxy);//洋老板代理
app.use('/draw/*', drawProxy);//营销系统代理
app.use('/gateway/*', gatewayProxy);//秒杀代理
app.use('/third-party/*', thirdPartyProxy);//代理

// Render your site
app.get('/index.htm', function (req, res) {
    res.sendFile(__dirname + '/src/index.html');
});

app.listen(8099, () => {
    console.log('Listening on: http://localhost:8083');
});
posted @ 2019-11-12 10:24  我爱小明  阅读(144)  评论(0编辑  收藏  举报