From 8418f32bc800ef9a3252cf782f9543fc6abbd893 Mon Sep 17 00:00:00 2001 From: ronload <91997734+ronload@users.noreply.github.com> Date: Wed, 15 Apr 2026 17:51:03 +0800 Subject: [PATCH] fix(map): proxy all carto CDN requests to bypass CORS Carto CDN returns Access-Control-Allow-Origin with http:// instead of https://, blocking style, tile, sprite and glyph requests. Proxy all Carto URLs through Next.js rewrites via transformRequest so the browser makes same-origin requests only. Remove now-unused preconnect hints. --- next.config.ts | 10 +++++++--- src/app/layout.tsx | 15 +-------------- src/components/ui/map.tsx | 18 ++++++++++++++++-- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/next.config.ts b/next.config.ts index 765d934..d1193f5 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,11 +1,15 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { - async rewrites() { + rewrites() { return [ { - source: "/map-styles/:path*", - destination: "https://basemaps.cartocdn.com/gl/:path*", + source: "/map-cdn/basemaps/:path*", + destination: "https://basemaps.cartocdn.com/:path*", + }, + { + source: "/map-cdn/tiles/:path*", + destination: "https://tiles.basemaps.cartocdn.com/:path*", }, ]; }, diff --git a/src/app/layout.tsx b/src/app/layout.tsx index a78ca91..f56f6d6 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -68,20 +68,7 @@ export default function RootLayout({ suppressHydrationWarning className={`${geistSans.variable} ${geistMono.variable} h-full antialiased`} > - - - - - - + (function Map( attributionControl: { compact: true, }, + transformRequest: (url) => ({ url: proxyCartoUrl(url) }), ...props, ...viewport, });