Created
December 7, 2020 20:27
-
-
Save jgcmarins/ecbbfa61456a09b0ba56c56a94c87dc0 to your computer and use it in GitHub Desktop.
Koa middleware to measure response time and set X-Response-Time header
This file contains 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 async function responseTime(ctx, next) { | |
const start = new Date(); | |
await next(); | |
const ms = new Date() - start; | |
ctx.set('X-Response-Time', ms + 'ms'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment