geolocation
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v26View latest version
A helper function to read a visitor's IP address from x-forwarded-for headers
and lookup geolocation data from ip-api.
import { fetchGeolocation } from "https://esm.town/v/mattrossman/geolocation/main.ts";
export default async function (req: Request) {
const geolocation = await fetchGeolocation(req);
return new Response(`You're visiting from ${geolocation.city}`);
}