1
2
3
4
5
6
7
8
9
10
11
12
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
import process from "node:process";
export const distance = async (req) => {
const searchParams = new URL(req.url).searchParams;
const destinationA = encodeURIComponent(String(searchParams.get("a")).trim());
const destinationB = encodeURIComponent(String(searchParams.get("b")).trim());
const obj = await fetchJSON(
`https://maps.googleapis.com/maps/api/distancematrix/json?destinations=${destinationA}&origins=${destinationB}&units=imperial&key=${process.env.GOOGLE_MAPS_API_KEY}`,
);
return Response.json(obj);
};