-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHostInfoEndpoints.cs
40 lines (37 loc) · 1.49 KB
/
HostInfoEndpoints.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using BasicWebApi.Models;
using Microsoft.AspNetCore.Mvc;
namespace BasicWebApi.Endpoints
{
public static class HostInfoEndpoints
{
public static RouteGroupBuilder MapHostInfoApi(this RouteGroupBuilder group)
{
group.MapGet("/", GetHostInfo);
group.MapGet("/2", GetHostInfo2)
.WithName("GetHostInfo2")
.WithSummary("Returns host information to any client")
.WithDescription("Example endpoint which returns simple host information")
.Produces(200, typeof(HostInfo))
.WithOpenApi(operation => new(operation) { Deprecated = true });
return group;
}
[EndpointName("GetHostInfo")]
[EndpointSummary("Returns host information to any client")]
[EndpointDescription("Example endpoint which returns simple host information")]
[Produces(typeof(HostInfo))]
public static async Task<HostInfo> GetHostInfo([FromServices] IHttpContextAccessor httpContextAccessor)
{
return new HostInfo
{
HostIp = httpContextAccessor?.HttpContext?.Connection?.LocalIpAddress?.ToString()
};
}
public static async Task<HostInfo> GetHostInfo2([FromServices] IHttpContextAccessor httpContextAccessor)
{
return new HostInfo
{
HostIp = httpContextAccessor?.HttpContext?.Connection?.LocalIpAddress?.ToString()
};
}
}
}