Last active
September 14, 2026 12:17
-
-
Save perandre/973f8e07c79259b3f7d8a1c21efc7e73 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const RENDER_BASE = | |
| "https://sites.frontkom.io/render/plussmobil/plussmobil.no"; | |
| const OWNED = { | |
| // Forside | |
| "/": RENDER_BASE, | |
| // Eksisterende Frontkom-sider | |
| "/sommertilbud-halvpris": | |
| `${RENDER_BASE}/sommertilbud-halvpris`, | |
| "/kundeservice/utland": | |
| `${RENDER_BASE}/kundeservice/utland`, | |
| "/mobilt-bredband": | |
| `${RENDER_BASE}/mobilt-bredband`, | |
| "/mobilabonnement": | |
| `${RENDER_BASE}/mobilabonnement`, | |
| // Nye Frontkom-sider | |
| "/kundeservice/nykunde/esim": | |
| `${RENDER_BASE}/kundeservice/nykunde/esim`, | |
| "/familie": | |
| `${RENDER_BASE}/familie`, | |
| "/om-oss": | |
| `${RENDER_BASE}/om-oss`, | |
| "/fridata": | |
| `${RENDER_BASE}/fridata`, | |
| "/internett-pa-hytta": | |
| `${RENDER_BASE}/internett-pa-hytta`, | |
| "/kundeservice/esim": | |
| `${RENDER_BASE}/kundeservice/esim`, | |
| }; | |
| function normalizePath(pathname) { | |
| return pathname.replace(/\/+$/, "") || "/"; | |
| } | |
| export default { | |
| async fetch(request) { | |
| const url = new URL(request.url); | |
| const pathname = normalizePath(url.pathname); | |
| const origin = | |
| OWNED[pathname] ?? | |
| (pathname.startsWith("/mobilt-bredband/") | |
| ? `${RENDER_BASE}${pathname}` | |
| : null); | |
| if (!origin) return fetch(request); | |
| try { | |
| const target = new URL(origin); | |
| target.search = url.search; | |
| const upstream = await fetch(target, { | |
| redirect: "follow", | |
| headers: { | |
| "user-agent": request.headers.get("user-agent") || "", | |
| }, | |
| }); | |
| if (!upstream.ok) return fetch(request); | |
| const headers = new Headers(upstream.headers); | |
| headers.set("x-served-by", "frontkom-sites"); | |
| return new Response(upstream.body, { | |
| status: upstream.status, | |
| headers, | |
| }); | |
| } catch { | |
| return fetch(request); | |
| } | |
| }, | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment