Meilisearch Server Side

๐Ÿšจ๐Ÿšจ Breaking CHANGE ๐Ÿšจ๐Ÿšจ

From v0.4.0 and above, you access to Meilisearch with $meilisearch instead of event. ๐Ÿ›‘ const { serverMeilisearchClient } = event.context

โœ… $meilisearch

The aim is to optimize performance and avoid to create a new instance for each request, no more event.context binding.


Configuration

You can to manage documents, indexes or preferences from Nuxt server side. To do so, first enable it

nuxt.config.ts
meilisearch: {
  ...
  serverSideUsage: true, // default false
  adminApiKey: '<your_secret_key>',
  ...
}
You need to provide API KEY with ADMIN ACCESS

Usage

Now you can use the $meilisearch instance from your server side code.

Full exemple:

my-endpoint.ts

export default defineEventHandler(async (event) => {

  // read from body
  const body = await readBody(event)

  // Meiliseach is available with $meilisearch
  const meilisearchResponse = $meilisearch.index('books').addDocuments(body)

  return meilisearchResponse

})

Typescript

$meilisearch is full typed so you can enjoy the full power of typescript, autocomplete and intellisense.