summaryrefslogtreecommitdiffstats
path: root/api/WhatApi/Endpoints/BaseEndpoint.cs
blob: 4d8f9adb39a9a62cba9ee71abcfbd82a234017b5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
using System.Net;
using Microsoft.AspNetCore.Mvc;

namespace WhatApi.Endpoints;

[ApiController]
public class BaseEndpoint : ControllerBase
{
    protected IPAddress GetIp() => Request.Headers.TryGetValue("X-Forwarded-For", out var ip)
        ? IPAddress.Parse(ip.ToString())
        : HttpContext.Connection.RemoteIpAddress!;
}