51 lines
1.7 KiB
C#
51 lines
1.7 KiB
C#
using Api.Settings;
|
|
using Microsoft.AspNetCore.Cors;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace Api.Controllers
|
|
{
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
[EnableCors("FrontendOnly")]
|
|
public sealed class GoogleController : ControllerBase
|
|
{
|
|
private readonly GoogleSettings _googleSettings;
|
|
private readonly ILogger<GoogleController> _log;
|
|
|
|
public GoogleController(IOptions<GoogleSettings> options, ILogger<GoogleController> log)
|
|
{
|
|
_googleSettings = options.Value;
|
|
_log = log;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the Google Tag Manager ID used by the frontend for analytics and tracking.
|
|
/// </summary>
|
|
/// <returns>200 OK with the Tag Manager ID as a string.</returns>
|
|
[HttpGet("tagmanager")]
|
|
public async Task<IActionResult> GetTagManagerId(CancellationToken ct)
|
|
{
|
|
return Ok(_googleSettings.TagManagerId);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
/// <returns>200 OK with the maps API key as a string.</returns>
|
|
[HttpGet("maps")]
|
|
public async Task<IActionResult> GetMapKey(CancellationToken ct)
|
|
{
|
|
return Ok(_googleSettings.MapKey);
|
|
}
|
|
|
|
}
|
|
}
|