Skip to content

Instantly share code, notes, and snippets.

@gonzaleztroyano
Created May 16, 2023 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gonzaleztroyano/3fbd08b8b2998e52230ab749dbfadca8 to your computer and use it in GitHub Desktop.
Save gonzaleztroyano/3fbd08b8b2998e52230ab749dbfadca8 to your computer and use it in GitHub Desktop.
async function handleRequest(stop_requested) {
if (stop_requested > 1 && stop_requested < 99999) {
console.log("OK - " + stop_requested)
const destinationURL = 'https://www.emtmadrid.es/PMVVisor/pmv.aspx?stopnum=' + stop_requested + '&size=3&utm_source=pglez';
return Response.redirect(destinationURL, 302);
} else {
console.log("NOK - " + stop_requested)
const html = `<html> <head> <meta charset="utf-8"> <title>Visor de tiempos EMT</title> <style>body{font-family: 'Open Sans', 'Helvetica Neue', sans-serif;}img{max-width: 100vw; max-height: 100vw;}</style> </head> <body> <h1>Error en la petición</h1> <h2>Introduzca únicamente el número de parada como parámetro</h2> <br><img src="https://pub-e7a754c25f58400c88dabdb9d5a5b990.r2.dev/banner_emt_glez.png" alt="Imagen de ejemplo"> </body></html>`
return new Response(html, {
headers: {
'content-type': 'text/html;charset=UTF-8',},})}}
addEventListener('fetch', event => {
var request = event.request
var int_url = new URL(request.url);
var int_pathname = int_url.pathname.slice(1)
return event.respondWith(handleRequest(int_pathname));});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment