From 29708cd2a12a53ccf27a2ba625870ed5b2a8175a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=99=E6=BE=B3?= Date: Sun, 8 Mar 2026 11:13:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E4=BA=86=20FastAPI=20=E7=9A=84=20CORS?= =?UTF-8?q?=20=E4=B8=AD=E9=97=B4=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app.py b/app.py index ea162cd..6d1faf4 100644 --- a/app.py +++ b/app.py @@ -3,6 +3,7 @@ import math from fastapi import FastAPI +from fastapi.middleware.cors import CORSMiddleware from pyproj import CRS from morecantile import tms, TileMatrixSet from rio_tiler.io import Reader @@ -38,6 +39,18 @@ app = FastAPI( description="Mars MGS MOLA Color-Shaded Relief global tile server powered by Titiler", ) +# Configure CORS +app.add_middleware( + CORSMiddleware, + allow_origins=[ + "http://digitalmars.com.cn", + "https://digitalmars.com.cn", + ], + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + # Create COG Tiler with Mars TMS support cog = TilerFactory( reader=Reader,