Skip to content

beforeResponse hook does not work for Nuxt3 /server/api #8

@andrewspy

Description

@andrewspy

I wanted to compress a large JSON response from /server/api, but useCompression() does not seem to work with beforeResponse hook in Nuxt3. Code as follow:

nitro.hooks.hook('beforeResponse', async (event, response) => {
  if (!event.path.startsWith('/api/')) return

  await useCompression(event, response)
})

According to Nitro doc below, it should work as expected, did I miss something? Thanks!

https://nitro.build/guide/plugins#available-hooks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions