Skip to content

fix(map): proxy all carto CDN requests to bypass CORS#19

Merged
ronload merged 1 commit into
mainfrom
fix/map-cors-proxy-all
Apr 15, 2026
Merged

fix(map): proxy all carto CDN requests to bypass CORS#19
ronload merged 1 commit into
mainfrom
fix/map-cors-proxy-all

Conversation

@ronload

@ronload ronload commented Apr 15, 2026

Copy link
Copy Markdown
Owner

Summary

Production (https://zipkit.app) 遭遇 Carto CDN 的 CORS 問題 -- CDN 回傳的 Access-Control-Allow-Originhttp://zipkit.app(缺少 TLS),導致 style、tiles、sprites、glyphs 全部被瀏覽器阻擋。

#18 只代理了 style.json,但 style 內部引用的 tile metadata、sprite、glyph 等資源也來自同樣的 Carto 網域,同樣被 CORS 阻擋。

此 PR 透過 Next.js rewrites + MapLibre transformRequest 將所有 basemaps.cartocdn.comtiles.basemaps.cartocdn.com 請求代理到同源路徑 /map-cdn/*,徹底繞過 CORS。同時移除不再需要的 preconnect hints。

Test plan

  • pnpm dev -> Network tab 確認所有地圖請求走 /map-cdn/...
  • 切換 light/dark 主題,地圖正常渲染
  • 部署至 preview -> 確認 console 無 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.
@vercel

vercel Bot commented Apr 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
zipkit Ready Ready Preview, Comment Apr 15, 2026 9:55am

@ronload ronload merged commit 4e93904 into main Apr 15, 2026
3 checks passed
@ronload ronload deleted the fix/map-cors-proxy-all branch April 15, 2026 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant