Skip to content

Commit ea310c9

Browse files
committed
feat: Add optional logging for all server-side requests
1 parent 706a4f2 commit ea310c9

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

nuxt.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export default defineNuxtConfig({
3232
},
3333

3434
runtimeConfig: {
35+
logRequests: true,
3536
serverHostUrl: "http://localhost:8080",
3637
provider: {
3738
local: {

server/plugins/log.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default defineNitroPlugin((nitroApp) => {
2+
nitroApp.hooks.hook('request', (event) => {
3+
// Check if requests logging is enabled in config
4+
if (useRuntimeConfig().logRequests) {
5+
// Log all requests, except nuxt logic and sensitive callback info
6+
if (!event.path.includes('_nuxt') && !event.path.includes('/callback')) {
7+
console.log('[KPI]', event.method, event.path)
8+
}
9+
}
10+
})
11+
})

0 commit comments

Comments
 (0)