(request: FastifyRequest, reply: FastifyReply)
| 480 | } |
| 481 | |
| 482 | export async function getGeo(request: FastifyRequest, reply: FastifyReply) { |
| 483 | const { ip, header } = getClientIpFromHeaders(request.headers); |
| 484 | const others = await Promise.all( |
| 485 | DEFAULT_IP_HEADER_ORDER.map(async (header) => { |
| 486 | const { ip } = getClientIpFromHeaders(request.headers, header); |
| 487 | return { |
| 488 | header, |
| 489 | ip, |
| 490 | geo: await getGeoLocation(ip), |
| 491 | }; |
| 492 | }), |
| 493 | ); |
| 494 | |
| 495 | if (!ip) { |
| 496 | return reply.status(400).send('Bad Request'); |
| 497 | } |
| 498 | const geo = await getGeoLocation(ip); |
| 499 | return reply.status(200).send({ |
| 500 | selected: { |
| 501 | geo, |
| 502 | ip, |
| 503 | header, |
| 504 | }, |
| 505 | ...others.reduce( |
| 506 | (acc, other) => { |
| 507 | acc[other.header] = other; |
| 508 | return acc; |
| 509 | }, |
| 510 | {} as Record<string, { ip: string; header: string; geo: GeoLocation }>, |
| 511 | ), |
| 512 | }); |
| 513 | } |
| 514 | |
| 515 | export async function getOgImage( |
| 516 | request: FastifyRequest<{ |
nothing calls this directly
no test coverage detected