feat: support separate AMAP_JS_API_KEY for JS SDK proxy
Some checks are pending
Security Scan / scout (push) Waiting to run

- AmapProxyController now reads AMAP_JS_API_KEY first, falls back to AMAP_WEB_SERVICE_KEY
- Update .env.example to document both keys
This commit is contained in:
jubnl 2026-07-11 20:01:52 +08:00
parent 29f6c4275d
commit 760f1ab9e8
2 changed files with 10 additions and 5 deletions

View File

@ -45,7 +45,8 @@ DEMO_MODE=false # Demo mode - resets data hourly
# UNSPLASH_ACCESS_KEY= # Optional Unsplash Access Key for trip-cover and place-image search. Without one, TREK uses Unsplash's unauthenticated endpoint, which some datacenter/VPS IPs get blocked from (#1449). Get a free key at unsplash.com/developers. Overrides any key set per-admin in Admin > Settings. Can also be configured there instead of here.
# AMAP_WEB_SERVICE_KEY= # Required. Amap (Gaode Maps) Web Service API key for maps, places, routing, and transit services. Get one at https://console.amap.com/dev/
# AMAP_WEB_SERVICE_KEY= # Required. Amap (Gaode Maps) Web Service API key for place search, routing, transit, and geocoding. Get one at https://console.amap.com/dev/
# AMAP_JS_API_KEY= # Required for the Amap JS map component. Falls back to AMAP_WEB_SERVICE_KEY if not set. Apply for a "JS API" key at https://console.amap.com/dev/
# OVERPASS_URL= # Deprecated — maps service uses Amap instead. Ignored when AMAP_WEB_SERVICE_KEY is set.

View File

@ -5,6 +5,10 @@ const AMAP_JS_BASE = 'https://webapi.amap.com';
const AMAP_JS_PATH = '/maps';
const CACHE_MAX_AGE = 24 * 60 * 60;
function getJsKey(): string | undefined {
return process.env.AMAP_JS_API_KEY?.trim() || process.env.AMAP_WEB_SERVICE_KEY?.trim();
}
@Controller('api/maps')
export class AmapProxyController {
private jsCache: { body: string; contentType: string } | null = null;
@ -12,9 +16,9 @@ export class AmapProxyController {
@Get('amap-js')
async serveAmapJs(@Query() query: Record<string, string>, @Res() res: Response) {
const key = process.env.AMAP_WEB_SERVICE_KEY?.trim();
const key = getJsKey();
if (!key) {
res.status(503).json({ error: 'AMap service not configured' });
res.status(503).json({ error: 'AMap JS API key not configured' });
return;
}
@ -61,9 +65,9 @@ export class AmapProxyController {
@All('amap-proxy/*')
async proxyAmap(@Req() req: Request, @Res() res: Response) {
const key = process.env.AMAP_WEB_SERVICE_KEY?.trim();
const key = getJsKey();
if (!key) {
res.status(503).json({ error: 'AMap service not configured' });
res.status(503).json({ error: 'AMap JS API key not configured' });
return;
}