• Nodejs http-proxy代理实战应用


    var https = require('https');
    var express = require('express');
    var app = express()
    var http = require('http'),
        httpProxy = require('http-proxy');
    var proxy = httpProxy.createProxyServer({ changeOrigin: true});  
    
    app.all('/apis/*', function (req, res, next) {
        var target = req.originalUrl.replace("/apis/", "");
        // Change this API url to suit your project
        var url = `/${target}`;
        req.url = url;
        console.log(url);
        delete req.headers.host;
        proxy.web(req, res, { target: 'http://localhost', changeOrigin: true });  
    })
    
    
    var server = app.listen(8080, function () {
        var host = server.address().address;
        var port = server.address().port;
        console.log('Example app listening at http://%s:%s', host, port);
    });
    

      changeOrigin: true   和  req.url = '处理后的url'

    var https = require('https');var express = require('express');var app = express()var http = require('http'),    httpProxy = require('http-proxy');var proxy = httpProxy.createProxyServer({ changeOrigin: true});  
    app.all('/apis/*', function (req, res, next) {    var target = req.originalUrl.replace("/apis/", "");    // Change this API url to suit your project    var url = `/${target}`;    req.url = url;    console.log(url);    delete req.headers.host;    proxy.web(req, res, { target: 'http://localhost', changeOrigin: true });  })

    var server = app.listen(8080, function () {    var host = server.address().address;    var port = server.address().port;    console.log('Example app listening at http://%s:%s', host, port);});

  • 相关阅读:
    (五)Hibernate 操作对象
    (四)关联关系一对多映射
    (三)映射对象标识符(OID)
    随机取数据
    Delphi的时间处理
    调用MYSQL存储过程实例
    php接收数据
    NodeJS入门
    idHTTP访问百度
    delphi 从TWebBrowser WebBrowser得到全部html源码
  • 原文地址:https://www.cnblogs.com/guxuelong/p/9009703.html
Copyright © 2020-2023  润新知