using Asp.Versioning;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace InboxIntel.Api.Controllers;
///
/// Public metadata the SPA reads on load to decide whether to show the dev
/// banner. devMode falls back to the hosting environment when App:DevMode is
/// unset, and can be forced on/off via the App:DevMode config / App__DevMode env.
///
[ApiController]
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/app")]
public class AppInfoController : ControllerBase
{
private readonly IConfiguration _config;
private readonly IWebHostEnvironment _env;
public AppInfoController(IConfiguration config, IWebHostEnvironment env)
{
_config = config;
_env = env;
}
[HttpGet("info")]
[AllowAnonymous]
public IActionResult Info()
{
var devMode = _config.GetValue("App:DevMode") ?? _env.IsDevelopment();
// V-13: when NOT in dev mode, disclose nothing beyond the flag to anonymous
// callers. The dev banner (the only consumer of environment/maxMessages) only
// renders when devMode is true, so this preserves the feature without leaking
// the environment name or sync cap in production.
if (!devMode)
return Ok(new { devMode = false });
return Ok(new
{
devMode = true,
environment = _env.EnvironmentName,
maxMessages = _config.GetValue("GmailSync:MaxMessages")
});
}
}