2016-07-12 136 views
2

我通过我的快递配置以下设置进行代理我的API添加自定义标题为“请求”

// Proxy api calls 
    app.use('/api', function (req, res) { 
    let url = config.API_HOST + req.url 
    req.pipe(request(url)).pipe(res) 
    }) 

在这里config.API_HOST解决了我的API URL和req.url一些端点即/users我试过以下的NPM文件为request,并设置了我的头,像这样

// Proxy api calls 
    app.use('/api', function (req, res) { 
    let options = { 
     url: config.API_HOST + req.url, 
     options: { 'mycustomheader': 'test' } 
    } 
    req.pipe(request(options)).pipe(res) 
    }) 

但我无法看到网络下的Chrome浏览器开发工具,我的自定义标题。

回答

3

之所以能够取得这样说

app.use('/api', function (req, res) { 
    let url = config.API_HOST + req.ur 
    req.headers['someHeader'] = 'someValue' 
    req.pipe(request(url)).pipe(res) 
    }) 
相关问题