feat: support separate AMAP_JS_API_KEY for JS SDK proxy
Some checks are pending
Security Scan / scout (push) Waiting to run
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:
parent
29f6c4275d
commit
760f1ab9e8
@ -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.
|
# 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.
|
# OVERPASS_URL= # Deprecated — maps service uses Amap instead. Ignored when AMAP_WEB_SERVICE_KEY is set.
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,10 @@ const AMAP_JS_BASE = 'https://webapi.amap.com';
|
|||||||
const AMAP_JS_PATH = '/maps';
|
const AMAP_JS_PATH = '/maps';
|
||||||
const CACHE_MAX_AGE = 24 * 60 * 60;
|
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')
|
@Controller('api/maps')
|
||||||
export class AmapProxyController {
|
export class AmapProxyController {
|
||||||
private jsCache: { body: string; contentType: string } | null = null;
|
private jsCache: { body: string; contentType: string } | null = null;
|
||||||
@ -12,9 +16,9 @@ export class AmapProxyController {
|
|||||||
|
|
||||||
@Get('amap-js')
|
@Get('amap-js')
|
||||||
async serveAmapJs(@Query() query: Record<string, string>, @Res() res: Response) {
|
async serveAmapJs(@Query() query: Record<string, string>, @Res() res: Response) {
|
||||||
const key = process.env.AMAP_WEB_SERVICE_KEY?.trim();
|
const key = getJsKey();
|
||||||
if (!key) {
|
if (!key) {
|
||||||
res.status(503).json({ error: 'AMap service not configured' });
|
res.status(503).json({ error: 'AMap JS API key not configured' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,9 +65,9 @@ export class AmapProxyController {
|
|||||||
|
|
||||||
@All('amap-proxy/*')
|
@All('amap-proxy/*')
|
||||||
async proxyAmap(@Req() req: Request, @Res() res: Response) {
|
async proxyAmap(@Req() req: Request, @Res() res: Response) {
|
||||||
const key = process.env.AMAP_WEB_SERVICE_KEY?.trim();
|
const key = getJsKey();
|
||||||
if (!key) {
|
if (!key) {
|
||||||
res.status(503).json({ error: 'AMap service not configured' });
|
res.status(503).json({ error: 'AMap JS API key not configured' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user