MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / getGeo

Function getGeo

apps/api/src/controllers/misc.controller.ts:482–513  ·  view source on GitHub ↗
(request: FastifyRequest, reply: FastifyReply)

Source from the content-addressed store, hash-verified

480}
481
482export 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
515export async function getOgImage(
516 request: FastifyRequest<{

Callers

nothing calls this directly

Calls 4

getClientIpFromHeadersFunction · 0.90
getGeoLocationFunction · 0.90
mapMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected