algolia / algoliasearch-client-javascript

⚡️ A fully-featured and blazing-fast JavaScript API client to interact with Algolia.
https://www.algolia.com/doc/api-client/javascript/getting-started/
MIT License
1.33k stars 222 forks source link

X-Forwarded-For issue #129

Closed Nagriar closed 9 years ago

Nagriar commented 9 years ago

When you set header X-Forwarded-For with the method setExtraHeader, the header is passed via the query string parameters. It should go directly via the headers.

vvo commented 9 years ago

All headers are passed via query string to avoid OPTION requests (for searches).

We could force headers passed to setExtraHeader to be passed via real headers but I wonder if this would break some of our website code @redox ? Or trigger option request on the dashboard (wich may be already the case or may be acceptable)

Or we could add an extra option to force real header but it sounds weird.

vvo commented 9 years ago

This was a Node.js requirement and in Node.js everything is passed with http headers (not query string).

Also for future references, in the browser setting this header (or any custom header) would trigger an OPTION request.

See http://www.html5rocks.com/en/tutorials/cors/#toc-types-of-cors-requests

davidgacc commented 1 year ago

hi people,

I am trying to add headers: {'X-Forwarded-For': ip.toString() }, , in order to get the total users as total metric in algolia. however i dont see any changes in total users in the dashboard.

I put a logs..and i got the : ip: 10.101.53.4, so i am receiving the ip as well.

this is the block code :

 const products = await index.search<AlgoliaOutputDocument>('', {
    headers: {'X-Forwarded-For': ip.toString() },
    filters: filtersString,
    distinct: false,
    hitsPerPage: 1000,
    numericFilters: numericFilters.length ? numericFilters : undefined,
    attributesToHighlight: [],
    attributesToRetrieve: ['*', '-sku.slug', '-sku.description', '-sku.created_at']
  });

thank you for your help.