Skip to content

Conversation

@half2me
Copy link

@half2me half2me commented Jul 13, 2021

This adds the option to specify what function to use for fetch requests.
Itt adds compatibility for using AppSearch in SvelteKit load functions

Backwards compatible, but allows to specify a custom fetch function per request.

const fetchFn = require('node-fetch')
const result = await client.search(query.get('q'), options, fetchFn)

Or uses the globally available fetch if not specified:

const result = await client.search(query.get('q'), options)

Example usage in SvelteKit load function:

// index.svelte

<script context="module">
import { createClient } from '@elastic/app-search-javascript'
const client = createClient({})

export const load = async ({ fetch }) => {
  const result = await client.search('foo', {}, fetch)
  return { props: { result } }
}
</script>

<script>
export let result
</script>

<pre>
  {JSON.stringify(result, null, 2)}
</pre>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant