From ee04608e78a5e4c7ce83650b164756a19c35588a Mon Sep 17 00:00:00 2001 From: ronload <91997734+ronload@users.noreply.github.com> Date: Wed, 15 Apr 2026 17:44:39 +0800 Subject: [PATCH] fix(map): proxy carto style requests to bypass CORS mismatch Carto CDN returns Access-Control-Allow-Origin with http:// instead of https://, causing CORS failures on production. Route style.json requests through a Next.js rewrite so the browser makes same-origin requests. --- next.config.ts | 9 ++++++++- src/components/ui/map.tsx | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/next.config.ts b/next.config.ts index e9ffa30..765d934 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,7 +1,14 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { - /* config options here */ + async rewrites() { + return [ + { + source: "/map-styles/:path*", + destination: "https://basemaps.cartocdn.com/gl/:path*", + }, + ]; + }, }; export default nextConfig; diff --git a/src/components/ui/map.tsx b/src/components/ui/map.tsx index 69dd287..5f181cf 100644 --- a/src/components/ui/map.tsx +++ b/src/components/ui/map.tsx @@ -22,8 +22,8 @@ import { X, Minus, Plus, Locate, Maximize, Loader2 } from "lucide-react"; import { cn } from "@/lib/utils"; const defaultStyles = { - dark: "https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json", - light: "https://basemaps.cartocdn.com/gl/positron-gl-style/style.json", + dark: "/map-styles/dark-matter-gl-style/style.json", + light: "/map-styles/positron-gl-style/style.json", }; type Theme = "light" | "dark";