geoip: fix service register

This commit is contained in:
undefined committed 2022-10-05 00:19:44 +08:00
1 parent d94e3e650a
commit 41e10e49f5
1 file changed
+5 -3
+5 -3
View File
@@ -13,8 +13,7 @@ export interface Result {
display: string display: string
} }
export function apply() { class GeoIPService extends Service {
Context.service('geoip', class GeoIPService extends Service {
provider = '<a href="http://www.maxmind.com" target="_blank">MaxMind</a>'; provider = '<a href="http://www.maxmind.com" target="_blank">MaxMind</a>';
lookup(ip: string, locale: string): Result { lookup(ip: string, locale: string): Result {
const res: any = reader.get(ip); const res: any = reader.get(ip);
@@ -30,5 +29,8 @@ export function apply() {
ret.display = `${ret.continent} ${ret.country}${ret.city ? ` ${ret.city}` : ''}`; ret.display = `${ret.continent} ${ret.country}${ret.city ? ` ${ret.city}` : ''}`;
return ret; return ret;
} }
}); }
export function apply(ctx: Context) {
Context.service('geoip', GeoIPService);
ctx.geoip = new GeoIPService(ctx, 'geoip', true);
} }