marisanity
marisanity

Reputation: 23

Setting request headers with Falcor

The documented way of setting request headers to Falcor HttpDataSource is not working out for me. It might be that I just have a silly mistake somewhere as Falcor is completely new concept for me.

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

These I checked out already: How to send auth tokens from the client with Falcor https://github.com/ekosz/redux-falcor/issues/7

I also tried to set the request headers from onBeforeRequest but that didn't make a difference. The headers I send to the server will go under 'access-control-request-headers'. And by that I mean only the header names are visible but the values are nowhere to be seen or accessed.

Client side:

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);
            });

And this I get when I console log the headers from the server side:

{ 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' }

And when I log req.header('x-auth-token') I get undefined, but when I log this req.header('access-control-request-headers'); I get x-auth-token as result.

Upvotes: 0

Views: 200

Answers (1)

James Conkling
James Conkling

Reputation: 3673

It looks like you are using the HttpDataSource from the falcor package. Try installing falcor-http-datasource and using that version instead. It's possible that the HttpDataSource bundled with the main falcor package is an older version.

e.g.

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"
        }
    })
});

Upvotes: 0

Related Questions