使用Falcor设置请求标头

时间:2019-03-27 21:40:30

标签: javascript node.js falcor falcor-router

记录的将请求标头设置为Falcor HttpDataSource的方法对我来说不可行。因为Falcor对我来说是全新的概念,所以我可能在某个地方犯了一个愚蠢的错误。

文档: https://github.com/Netflix/falcor-http-datasource#readme

这些我已经签出: How to send auth tokens from the client with Falcor https://github.com/ekosz/redux-falcor/issues/7

我还尝试从onBeforeRequest设置请求标头,但这没有什么区别。我发送到服务器的标头将位于“ access-control-request-headers”下。而且,我的意思是仅标题名称可见,但是值无处可见或无法访问。

客户端:

const model = new falcor.Model({
            source: new falcor.HttpDataSource('http://localhost:3001/api/users/model.json', {
                headers: {
                    'x-auth-token': "secret"
                }
            })
        });


model.get(["gamesById", ['5c4cb04fb7ccdd14a81cfe89'], ['name']])
            .then(function (response) {
                console.log(response);
            });

这是我从服务器端控制台登录标头时得到的:

{ host: 'localhost:3001',
  connection: 'keep-alive',
  'access-control-request-method': 'GET',
  origin: 'http://localhost:63342',
  'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko
) Chrome/73.0.3683.86 Safari/537.36',
  'access-control-request-headers': 'x-auth-token',
  accept: '*/*',
  referer: 'http://localhost:63342/gamebase-backend/index.html?_ijt=mssfaptvvjpofa44aqm1n9dt1v',

  'accept-encoding': 'gzip, deflate, br',
  'accept-language': 'fi-FI,fi;q=0.9,en-US;q=0.8,en;q=0.7,la;q=0.6' }

登录req.header('x-auth-token')时得到undefined,但是登录req.header('access-control-request-headers');时得到x-auth-token

1 个答案:

答案 0 :(得分:0)

您似乎正在使用falcor软件包中的HttpDataSource。尝试安装falcor-http-datasource并改用该版本。与主要falcor软件包捆绑在一起的HttpDataSource可能是较旧的版本。

例如

import falcor from 'falcor';
import HttpDataSource from 'falcor-http-datasource';

const model = new falcor.Model({
    source: new HttpDataSource('http://localhost:3001/api/users/model.json', {
        headers: {
            'x-auth-token': "secret"
        }
    })
});