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 miliseconds.
main.ts
https://mattrossman--2926a2bc47b811f0a07976b3cceeab13.web.val.run
A helper function to fetch geolocation data from ip-api based on a visitor's IP address
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}`);
}