Skip to content

Commit

Permalink
feat: add an API to inspect request's IP address (#110)
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Bajtoš <[email protected]>
  • Loading branch information
bajtos authored Oct 23, 2023
1 parent 261b28e commit 32a264a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const handler = async (req, res, client, getCurrentRound, domain) => {
await getMeridianRoundDetails(req, res, client, segs[2], segs[3])
} else if (segs[0] === 'rounds' && req.method === 'GET') {
await getRoundDetails(req, res, client, getCurrentRound, segs[1])
} else if (segs[0] === 'inspect-request' && req.method === 'GET') {
await inspectRequest(req, res)
} else {
notFound(res)
}
Expand Down Expand Up @@ -343,6 +345,16 @@ const redirect = (res, location) => {
res.end()
}

export const inspectRequest = async (req, res) => {
await json(res, {
remoteAddress: req.socket.remoteAddress,
flyClientAddr: req.headers['fly-client-ip'],
cloudfareAddr: req.headers['cf-connecting-ip'],
forwardedFor: req.headers['x-forwarded-for'],
headers: req.headersDistinct
})
}

export const createHandler = async ({
client,
logger,
Expand Down

0 comments on commit 32a264a

Please sign in to comment.