Last active
February 23, 2023 21:17
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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