Skip to content

Instantly share code, notes, and snippets.

@rimiti rimiti/ipstack.ts

Last active Jul 31, 2020
Embed
What would you like to do?
Typescript implementation of ipstack
import axios, { AxiosResponse } from 'axios';
import { config } from '../config';
import { Sentry } from '../libs/sentry';
/**
* @description Ip Stack API response
*/
interface IIpStackResponse {
latitude: number;
longitude: number;
}
/**
* @description Return IP geolocation
* @param ip {string} IP address
* @returns
*/
async function getGeolocationFromIp(ip: string): Promise<IIpStackResponse> {
try {
const { data }: AxiosResponse = await axios.get(`https://api.ipstack.com/${ip}`, {
headers: {
access_key: config.ipStack.token,
},
});
return data;
} catch (error) {
Sentry.captureException(error);
throw error;
}
}
export { getGeolocationFromIp, IIpStackResponse };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.