首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >正在修改代理HTTP响应

正在修改代理HTTP响应
EN

Stack Overflow用户
提问于 2018-06-08 14:59:26
回答 1查看 26关注 0票数 0

我有一个启动dev代理服务器的gulpfile。

代码语言:javascript
复制
gulp.task('dumbserver', ()=> {
    const express = require('express');
    const httpProxy = require('http-proxy');
    const app = express();
    const proxy = httpProxy.createProxyServer();

    app.use('/api', function (req, res) {
        proxy.web(req, res, {target: 'https://bos1-vcd-sp-static-199-8.eng.vmware.com/api', secure: false},
            (e) => console.log('error', e)
        );
    });
    return app.listen(8080, function () {
        console.log('Server started on port 8080.');
    });
});

当我直接打电话给https://bos1-vcd-sp-static-199-8.eng.vmware.com/api/session的邮递员时,我会得到以下有效负载:

<Session locationId="86171c79-e8f0-4c06-a0a8-4bc7fde76915@7bcf706c-d90f-4e1b-b0cc-b2a13db3e618" org="juan" roles="System Administrator" user="administrator" userId="urn:vcloud:user:7b5f0241-f597-4851-8cae-655a15afde24" href="https://bos1-vcd-sp-static-199-8.eng.vmware.com/api/session" type="application/vnd.vmware.vcloud.session+xml"> <Link rel="down" href="https://bos1-vcd-sp-static-199-8.eng.vmware.com/api/org/" type="application/vnd.vmware.vcloud.orgList+xml"/> <Link rel="remove" href="https://bos1-vcd-sp-static-199-8.eng.vmware.com/api/session"/> <Link rel="down" href="https://bos1-vcd-sp-static-199-8.eng.vmware.com/api/admin/" type="application/vnd.vmware.admin.vcloud+xml"/> <Link rel="down" href="https://bos1-vcd-sp-static-199-8.eng.vmware.com/api/admin/extension" type="application/vnd.vmware.admin.vmwExtension+xml"/> <Link rel="nsx" href="https://bos1-vcd-sp-static-199-8.eng.vmware.com/network" type="application/xml"/> <Link rel="openapi" href="https://bos1-vcd-sp-static-199-8.eng.vmware.com/cloudapi" type="application/json"/> </Session>

然而,当我用邮递员打电话到localhost:8080/api/session时,最后两个链接被改写为

代码语言:javascript
复制
<Link rel="nsx" href="https://localhost:8080/network" type="application/xml"/>
<Link rel="openapi" href="https://localhost:8080/cloudapi" type="application/json"/>

但是其他的链接都没有被重写。

对可能发生的事有什么建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-11 12:42:12

结果是,http-proxy添加了一个主机头。生成链接的服务器端代码使用该主机标头(如果可用)作为基本URL,覆盖配置的值。

如果不删除这个问题,希望http为请求添加一个主机头这一事实可能会导致代码中的错误。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50763402

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档