🐛fix:修复正式环境没有关闭SWAGGER

This commit is contained in:
yubaolee
2025-09-12 20:19:57 +08:00
parent 57546e5175
commit 23de2ae7e2
4 changed files with 124 additions and 68 deletions

View File

@@ -0,0 +1,41 @@
using System;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Hosting;
namespace OpenAuth.WebApi.Controllers
{
/// <summary>
/// 系统信息相关接口
/// </summary>
[Route("api/[controller]/[action]")]
[ApiController]
public class SystemController : ControllerBase
{
private readonly IHostEnvironment _environment;
public SystemController(IHostEnvironment environment)
{
_environment = environment;
}
/// <summary>
/// 获取系统环境信息
/// </summary>
/// <returns></returns>
[HttpGet]
[AllowAnonymous]
public IActionResult GetEnvironmentInfo()
{
return Ok(new
{
EnvironmentName = _environment.EnvironmentName,
IsDevelopment = _environment.IsDevelopment(),
IsProduction = _environment.IsProduction(),
IsStaging = _environment.IsStaging(),
SwaggerEnabled = _environment.IsDevelopment(), // Swagger 只在开发环境启用
Timestamp = DateTime.Now
});
}
}
}