Skip to content

Instantly share code, notes, and snippets.

@jhonata-menezes
Last active February 23, 2023 21:17
Show Gist options
  • Save jhonata-menezes/68cab93bfa9a7a9949a697b73aefec1f to your computer and use it in GitHub Desktop.
Save jhonata-menezes/68cab93bfa9a7a9949a697b73aefec1f to your computer and use it in GitHub Desktop.
Log in the server side path, status code and response time in a nuxt 3 application, create this file inside the "plugins" folder
export default defineNuxtPlugin(nuxtApp => {
addRouteMiddleware('request-logger', () => {
const start = new Date();
nuxtApp.hook('app:rendered', (renderContext) => {
const { req, res } = (renderContext.ssrContext.event.node)
res.on('close', () => {
const message = `${res.statusCode} ${req.url} ${new Date() - start} ms`
console.info(message)
})
})
}, { global: true })
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment