using Api.Models.Settings;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
namespace Api.Controllers
{
///
/// Provides simple endpoints to expose Google related public keys used by
/// the frontend (for example Google Analytics tag id and Maps API key).
/// These endpoints return only public values safe to be exposed to clients.
///
[ApiController]
[Route("api/[controller]")]
[EnableCors("FrontendOnly")]
public sealed class GoogleController : ControllerBase
{
private readonly GoogleSettings _googleSettings;
private readonly ILogger _log;
public GoogleController(IOptions options, ILogger log)
{
_googleSettings = options.Value;
_log = log;
}
///
/// Returns the Google Tag Manager ID used by the frontend for analytics and tracking.
///
/// 200 OK with the Tag Manager ID as a string.
[HttpGet("tagmanager")]
public async Task GetTagManagerId(CancellationToken ct)
{
return Ok(_googleSettings.TagManagerId);
}
///
/// Returns the Google Maps API key used by the frontend to load the
/// Maps JavaScript API. This key is expected to be restricted and
/// safe to expose for client-side usage.
///
/// 200 OK with the maps API key as a string.
[HttpGet("maps")]
public async Task GetMapKey(CancellationToken ct)
{
return Ok(_googleSettings.MapKey);
}
}
}