- main
- manifest
- deps
- main
- Install
- Run
import { Router } from "@fastly/expressly";
import { getGeolocationForIpAddress } from "fastly:geolocation";
const router = new Router();
router.get("(.*)", async (req, res) => {
let geo;
try {
geo = getGeolocationForIpAddress(req.ip);
} catch (error) {
console.error(error);
}
let offset = geo.utc_offset;
let tz_offset_iso8601 = offset;
req.headers.append("tz-offset-iso8601", tz_offset_iso8601);
let tz_hour = Math.round(offset / 100);
req.headers.append("tz-hour", tz_hour);
let tz_offset_hours = (offset % 100) / 60 + Math.round(offset / 100);
req.headers.append("tz-offset-hours", tz_offset_hours);
let tz_evenhour = Math.round(offset / 100 / 2) * 2;
req.headers.append("tz-evenhour", tz_evenhour);
res.send(await fetch(req, { backend: "origin_0" }));
});
router.listen();