From a3ba3f18fa783ef94e8800e512efc2018de1df5d Mon Sep 17 00:00:00 2001 From: Roman Tsisyk Date: Thu, 19 Aug 2021 12:33:36 +0300 Subject: [PATCH] Route North America to BackBlaze + CF --- src/index.ts | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 4c4e731..45d15a8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,5 @@ export {}; -const SERVERS = ['https://cdn-eu1.organicmaps.app/', 'https://cdn-eu2.organicmaps.app/', 'https://cdn.organicmaps.app/']; - addEventListener('fetch', (event) => { event.respondWith(handleRequest(event.request).catch((err) => new Response(err.stack, { status: 500 }))); }); @@ -10,10 +8,28 @@ async function handleRequest(request: Request) { const { pathname } = new URL(request.url); switch (pathname) { - case '/servers': - return new Response(JSON.stringify(SERVERS), { + case '/servers': { + let servers; + switch (request.cf?.continent) { + case 'NA': // North America + servers = [ + 'https://cdn4.organicmaps.app/', // BackBlaze US-West + CF, unmetered + 'https://cdn.organicmaps.app/', // Hetzner BareMetal DE unmetered + ]; + break; + default: + // Everything else + servers = [ + 'https://cdn-pl1.organicmaps.app/', // OVH PL, unmetered + 'https://cdn-fi1.organicmaps.app/', // Hetzner Cloud FI, 20TB + 'https://cdn-eu2.organicmaps.app/', // Hetzner Cloud DE, 20TB + 'https://cdn.organicmaps.app/', // Hetzner BareMetal DE unmetered + ]; + } + return new Response(JSON.stringify(servers), { headers: { 'Content-Type': 'application/json' }, }); + } } return new Response('', { status: 404 }); }