Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Readme

IATA Airport Code Map Redirector

I needed way redirect to a map for a given aiport given an IATA airport code.

This way is it's a simple proxy redirect and I can change if I want to use Google Maps or another service (or change zoom levels, etc) without having to update the link.

Usage:

1
2
3
4
5
6
7
8
9
10
11
12
13
export default async function(req: Request): Promise<Response> {
const query = new URL(req.url).searchParams;
const iata = query.get("iata") || query.get("q");
if (!iata) {
return new Response("Airport code not provided", { status: 400 });
}
const redirectUrl = `https://maps.google.com/?q=${iata.toUpperCase()}+airport`;
console.log("redirecting to", redirectUrl);
return Response.redirect(redirectUrl, 302);
}
dthyresson-airportcodemapredirector.web.val.run
July 26, 2024