Skip to content

Commit

Permalink
refactor: use @kikobeats/time-span dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Oct 8, 2023
1 parent 65ec020 commit c3be877
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"@keyvhq/core": "~2.1.0",
"@keyvhq/multi": "~2.1.0",
"@keyvhq/redis": "~2.1.0",
"@kikobeats/time-span": "~1.0.2",
"@microlink/mql": "~0.11.4",
"@microlink/ping-url": "~1.4.10",
"async-ratelimiter": "~1.3.11",
Expand Down
10 changes: 3 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

const timeSpan = require('@kikobeats/time-span')()
const debug = require('debug-logfmt')('unavatar')
const serveStatic = require('serve-static')
const createRouter = require('router-http')
Expand All @@ -14,11 +15,6 @@ const avatar = require('./avatar')

const { API_URL } = require('./constant')

const timestamp =
(start = process.hrtime.bigint()) =>
() =>
Math.round(Number(process.hrtime.bigint() - start) / 1e6)

const router = createRouter((error, req, res) => {
const hasError = error !== undefined
let statusCode = 404
Expand Down Expand Up @@ -46,7 +42,7 @@ router
},
require('./authentication'),
(req, res, next) => {
req.timestamp = timestamp()
req.timestamp = timeSpan()
req.query = Array.from(new URLSearchParams(req.query)).reduce(
(acc, [key, value]) => {
try {
Expand All @@ -62,7 +58,7 @@ router
debug(
`${req.ipAddress} ${new URL(req.url, API_URL).toString()} ${
res.statusCode
} ${req.timestamp()}ms`
} ${Math.round(req.timestamp())}ms`
)
})
next()
Expand Down

0 comments on commit c3be877

Please sign in to comment.