Skip to content

Commit

Permalink
with $HAFAS_REQ_RES_LOG_FILE, log HAFAS requests/responses to a file
Browse files Browse the repository at this point in the history
  • Loading branch information
derhuerst committed Nov 16, 2024
1 parent ec5fe78 commit 9ae650c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
createVbbHafas as createHafas,
defaults as vbbHafasDefaults,
} from 'vbb-hafas'
import {createWriteStream} from 'node:fs'
import createHealthCheck from 'hafas-client-health-check'
import Redis from 'ioredis'
import {createCachedHafasClient as withCache} from 'cached-hafas-client'
Expand Down Expand Up @@ -46,6 +47,21 @@ if (process.env.RANDOM_LOCAL_ADDRESSES_RANGE) {
}
}

if (process.env.HAFAS_REQ_RES_LOG_FILE) {
const hafasLogPath = process.env.HAFAS_REQ_RES_LOG_FILE
const hafasLog = createWriteStream(hafasLogPath, {flags: 'a'}) // append-only
hafasLog.on('error', (err) => console.error('hafasLog error', err))

customVbbProfile.logRequest = (ctx, req, reqId) => {
console.error(reqId, 'req', req.body + '') // todo: remove
hafasLog.write(JSON.stringify([reqId, 'req', req.body + '']) + '\n')
}
customVbbProfile.logResponse = (ctx, res, body, reqId) => {
console.error(reqId, 'res', body + '') // todo: remove
hafasLog.write(JSON.stringify([reqId, 'res', body + '']) + '\n')
}
}

let hafas = createHafas(
// seems like `vbb-rest` is being redirected
// pkg.name,
Expand Down

0 comments on commit 9ae650c

Please sign in to comment.