Algolia search not working from the client

I can’t seem to get Algolia search running from the server. I install Algolia from npm and use this code:

var algoliasearch = require('algoliasearch'); var client = algoliasearch('applicationID', 'apiKey'); var index = client.initIndex('indexName'); index.search('something', function searchDone(err, content) { console.log(err, content); });

and it gives me this error:

Refused to set unsafe header "connection" Refused to set unsafe header "accept-encoding" Refused to set unsafe header "content-length" XMLHttpRequest cannot load https://xxxxx-dsn.algolia.net/1/indexes/companies/query. Response to preflight request doesn't pass access control check: A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'http://localhost:3000' is therefore not allowed access. The credentials mode of an XMLHttpRequest is controlled by the withCredentials attribute.

I’ve seen people suggesting to run from the server via a Method, but I obviously don’t wanna hit the server for each search.

Any help would be greatly appreciated :slight_smile:

Same here.

it does work with the acemtp:algolia atmosphere package though.

but I’d like to go npm as much as I can.

1 Like

I have forked acemtp’s package and upgraded algoliaserach to 3.14.1

This is a workaround until I undersatnd why algoliaserach through pure npm fails.

you can find my fork here:

just clone it into your packages dir and do a meteor add teknologist:algolia

I hope this helps in the meantime…

1 Like

Thanks :slight_smile: I’d love to use npm as well, but I guess I’ll stick with that package for now.

Any idea how to fix this ?

Discussion with the Algolia folks: https://github.com/algolia/instantsearch.js/issues/1024

Reproduction: https://github.com/gwendall/meteor-algolia-instantsearch-bug

That should work:

var algoliasearch = require('algoliasearch/lite');

What worked for me (although it’s not pretty) is the following:

const algoliasearch = require("algoliasearch/dist/algoliasearchLite");