addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request) {
let html_content = "";
let html_style = "body{padding:6em; font-family: sans-serif;} h1{color:#0000ff;}";
html_content += "<p> asn: " + request.eo.geo.asn + "</p>";
html_content += "<p> countryName: " + request.eo.geo.countryName + "</p>";
html_content += "<p> countryCodeAlpha2: " + request.eo.geo.countryCodeAlpha2 + "</p>";
html_content += "<p> countryCodeAlpha3: " + request.eo.geo.countryCodeAlpha3 + "</p>";
html_content += "<p> countryCodeNumeric: " + request.eo.geo.countryCodeNumeric + "</p>";
html_content += "<p> regionName: " + request.eo.geo.regionName + "</p>";
html_content += "<p> regionCode: " + request.eo.geo.regionCode + "</p>";
html_content += "<p> cityName: " + request.eo.geo.cityName + "</p>";
html_content += "<p> Latitude: " + request.eo.geo.latitude + "</p>";
html_content += "<p> Longitude: " + request.eo.geo.longitude + "</p>";
let html = `<!DOCTYPE html>
<head>
<title> Geolocation: Hello World By Edge Functions.</title>
<style> ${html_style} </style>
</head>
<body>
<h1>Geolocation: Hello World By Edge Functions.</h1>
<p> Welcome to try out the geolocation feature of Edge Functions.</p>
${html_content}
</body>`;
return new Response(html, {
headers: {
"content-type": "text/html;charset=UTF-8",
},
});
}
Was this page helpful?