File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33import { Arrays , Objects } from 'cafe-utility'
44import { IncomingMessage , ServerResponse , createServer } from 'http'
55import fetch from 'node-fetch'
6+ import { metrics } from './metrics'
67import { Target , getHealthyTarget } from './target'
78import { RequestContext , ResponseContext } from './types'
89import { fetchWithTimeout , respondWithFetchPromise } from './utility'
@@ -38,7 +39,7 @@ function main() {
3839 try {
3940 await fetch ( target . url , { timeout : 10_000 } )
4041 response . statusCode = 200
41- response . end ( ' 200 OK' )
42+ response . end ( ` 200 OK - ${ metrics . requests } requests served` )
4243 return
4344 } catch ( error ) {
4445 target . lastErrorAt = Date . now ( )
@@ -66,6 +67,7 @@ function main() {
6667 const parsedBody = JSON . parse ( context . body )
6768 const id = parsedBody . id
6869 delete parsedBody . id
70+ metrics . requests ++
6971 const key = `${ target . url } _${ JSON . stringify ( parsedBody ) } `
7072 const cachedPromise = Objects . getFromFastIndexWithExpiracy (
7173 fastIndex ,
Original file line number Diff line number Diff line change 1+ export const metrics = {
2+ requests : 0
3+ }
You can’t perform that action at this time.
0 commit comments