2016-07-12 199 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) 
    }) 
相關問題