40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
using Expose.MyIT.Shared.Models.Stateless.Methods;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Expose.MyIT.Server.Controllers;
|
|
|
|
[ApiController]
|
|
public class ClientSettingsController : ControllerBase, IClientSettingsController
|
|
{
|
|
|
|
private readonly Models.AppSettings _AppSettings;
|
|
|
|
public ClientSettingsController(Models.AppSettings appSettings) => _AppSettings = appSettings;
|
|
|
|
[Route("api/[controller]")]
|
|
[HttpGet]
|
|
public string[] GetClientSettings()
|
|
{
|
|
List<string> results = new();
|
|
string? remoteIpAddress = Request.HttpContext.Connection?.RemoteIpAddress?.ToString();
|
|
if (!string.IsNullOrEmpty(remoteIpAddress))
|
|
results.Add(remoteIpAddress);
|
|
else
|
|
results.Add(nameof(remoteIpAddress));
|
|
if (!_AppSettings.IsDevelopment)
|
|
throw new Exception("Shouldn't expose!");
|
|
return results.ToArray();
|
|
}
|
|
|
|
[Route("api/[controller]/IpAddress")]
|
|
[HttpGet]
|
|
public string GetIpAddress()
|
|
{
|
|
string? result;
|
|
result = Request.HttpContext.Connection?.RemoteIpAddress?.ToString();
|
|
if (string.IsNullOrEmpty(result))
|
|
result = string.Empty;
|
|
return result;
|
|
}
|
|
|
|
} |