hono-geo-middleware
Version:
A geo middleware for Hono
51 lines (45 loc) • 1.36 kB
text/typescript
import * as hono from 'hono';
import { Context } from 'hono';
import { Env, Input } from 'hono/types';
interface Geo {
reqId?: string;
ip?: string;
city?: string;
country?: string;
countryCode?: string;
region?: string;
regionCode?: string;
latitude?: string;
longitude?: string;
continent?: string;
postalCode?: string;
metroCode?: string;
timezone?: string;
asn?: string;
idcRegion?: string;
/** flag emoji */
flag?: string;
}
interface ExtractorOptions {
}
type GeoExtractorFunc = (headers: Record<string, string>, c: Context, options?: ExtractorOptions) => Geo | null;
declare const extractorFuncsMap: {
vercel: GeoExtractorFunc;
cloudflare: GeoExtractorFunc;
'cloudflare-worker': GeoExtractorFunc;
netlify: GeoExtractorFunc;
cloudfront: GeoExtractorFunc;
};
type Extractor = (keyof typeof extractorFuncsMap) | GeoExtractorFunc;
declare module 'hono' {
interface ContextVariableMap {
geo: Geo;
}
}
interface GeoMiddlewareOptions {
extractors?: Extractor[];
extractorOption?: ExtractorOptions;
}
declare const GeoMiddleware: <E extends Env = any, P extends string = string, I extends Input = {}>(options?: GeoMiddlewareOptions) => hono.MiddlewareHandler<E, P, I>;
declare const getGeo: (c: Context) => Geo;
export { GeoMiddleware, getGeo };