Skip to content

Commit

Permalink
feat: calculate middleware execution time
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromtec committed Oct 23, 2024
1 parent d865b38 commit 80c972b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/core/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import storeConfig from 'discovery.config.default'
const redirectsClient = new RedirectsClient()

//cache-control: max-age=300, stale-while-revalidate=31536000

// faststore-redirects-time: 10
export async function middleware(request: NextRequest) {
const startTime = Date.now()
const { pathname } = request.nextUrl

const redirect = await redirectsClient.get(pathname)
Expand All @@ -24,6 +25,11 @@ export async function middleware(request: NextRequest) {
'public, max-age=300, stale-while-revalidate=31536000'
)

const endTime = Date.now()
const executionTime = endTime - startTime

response.headers.set('faststore-redirects-time', executionTime.toString())

return response
}

Expand Down

0 comments on commit 80c972b

Please sign in to comment.