import express, { Request, Response, Router } from 'express'; export default (): Router => { const router = express.Router(); /** * @swagger * /api/config: * get: * tags: * - Public API * summary: Get API configuration * description: Returns public API configuration including Mapbox access token for geocoding * responses: * 200: * description: API configuration retrieved successfully * content: * application/json: * schema: * $ref: '#/components/schemas/ApiConfig' * examples: * with_mapbox: * summary: Configuration with Mapbox token * value: * mapboxAccessToken: "pk.eyJ1IjoiZXhhbXBsZSIsImEiOiJhYmNkZWZnIn0.example" * hasMapbox: true * without_mapbox: * summary: Configuration without Mapbox token * value: * mapboxAccessToken: null * hasMapbox: false * 500: * description: Internal server error * content: * application/json: * schema: * $ref: '#/components/schemas/Error' */ router.get('/', (req: Request, res: Response): void => { console.log('📡 API Config requested'); const MAPBOX_ACCESS_TOKEN: string | undefined = process.env.MAPBOX_ACCESS_TOKEN || undefined; console.log('Mapbox token present:', !!MAPBOX_ACCESS_TOKEN); console.log('Mapbox token starts with pk:', MAPBOX_ACCESS_TOKEN?.startsWith('pk.')); res.json({ // Mapbox tokens are designed to be public (they have domain restrictions) mapboxAccessToken: MAPBOX_ACCESS_TOKEN || null, hasMapbox: !!MAPBOX_ACCESS_TOKEN // SECURITY: Google Maps API key is kept server-side only }); }); return router; };