使用 Falcor 设置请求 headers
Setting request headers with Falcor
将请求 headers 设置为 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 设置请求 headers 但这并没有什么不同。我发送到服务器的 headers 将在 'access-control-request-headers' 下。我的意思是只有 header 名称可见,但无法看到或访问这些值。
客户端:
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);
});
这是我在控制台从服务器端记录 header 时得到的:
{ 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
作为结果。
您似乎在使用 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"
}
})
});
将请求 headers 设置为 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 设置请求 headers 但这并没有什么不同。我发送到服务器的 headers 将在 'access-control-request-headers' 下。我的意思是只有 header 名称可见,但无法看到或访问这些值。
客户端:
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);
});
这是我在控制台从服务器端记录 header 时得到的:
{ 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
作为结果。
您似乎在使用 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"
}
})
});