Edson Feimberg
01/26/2022, 8:19 PMimport TypesenseInstantSearchAdapter from "typesense-instantsearch-adapter";
const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
server: {
apiKey: "xyz", // Be sure to use an API key that only allows search operations
nodes: [
{
host: "localhost",
port: "8108",
protocol: "http",
},
],
},
cacheSearchResultsForSeconds: 2 * 60, // Cache search results from server. Defaults to 2 minutes. Set to 0 to disable caching.
// The following parameters are directly passed to Typesense's search API endpoint.
// So you can pass any parameters supported by the search endpoint below.
// queryBy is required.
additionalSearchParameters: {
queryBy: "full_name",
},
});
const searchClient = typesenseInstantsearchAdapter.searchClient;
in this example, everything works perfectly in my app (even if i have to disable CORS in the browser)
import Typesense from 'typesense'
export default {
data() {
return {
queryString: '',
}
},
methods: {
search() {
const client = new Typesense.Client({
nodes: [
{
host: 'localhost',
port: '8108',
protocol: 'http',
},
],
apiKey: 'xyz',
connectionTimeoutSeconds: 2,
})
const searchParameters = {
q: 'Volvo',
query_by: 'name',
}
client.collections('brands').documents().search(searchParameters)
},
},
}
now in this example i get a lot of cors related errros in the console like:
_OPTIONShttp://localhost:8108/collections/brands/documents/search?q=Volvo&query_by=nameCORS Preflight Did Not Succeed_
_Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8108/collections/brands/documents/search?q=Volvo&query_by=name. (Reason: CORS preflight response did not succeed). Status code: 404._
am i missing something?Jason Bosco
01/26/2022, 8:20 PM--enable-cors
when starting Typesense serverJason Bosco
01/26/2022, 8:22 PMeven with cors disabled in my browser with a pluginSide note: I wasn't aware you could do this. Thought this was a browser built-in security feature
Edson Feimberg
01/26/2022, 8:52 PMEdson Feimberg
01/26/2022, 9:00 PMEdson Feimberg
01/26/2022, 9:01 PMJason Bosco
01/27/2022, 2:06 AM