From v1.4.0 and above, you access to Meilisearch with $meilisearch(event)
✅ $meilisearch(event)
Due about a change build process frm nitro, we need to pass the event to the function.
You can to manage documents, indexes or preferences from Nuxt server side. To do so, first enable it
meilisearch: {
...
serverSideUsage: true, // default false
adminApiKey: '<your_secret_key>',
...
}
Now you can use the $meilisearch(event) instance from your server side code.
Full exemple:
export default defineEventHandler(async (event) => {
// read from body
const body = await readBody(event)
// Meiliseach is available with $meilisearch
const meilisearchResponse = $meilisearch(event).index('books').addDocuments(body)
return meilisearchResponse
})
$meilisearch is full typed so you can enjoy the full power of typescript, autocomplete and intellisense.