feat(archival): add ping endpoint

This commit is contained in:
Collin M. Barrett 2020-10-04 14:19:39 -05:00
parent 1386474f18
commit 953113512c
8 changed files with 103 additions and 3 deletions

View file

@ -1,2 +1,2 @@
URLS=[ { url: 'http://localhost:8080/api/directory/v1/swagger.json', name: 'Directory' } ]
URLS=[{url:'http://localhost:8080/api/directory/v1/swagger.json',name:'Directory'},{url:'http://localhost:8080/api/archival/v1/swagger.json',name:'Archival'}]
URLS_PRIMARY_NAME=Directory

View file

@ -1,6 +1,18 @@
server {
listen 80 default_server;
location ^~ /api/archival/ {
rewrite ^/api/archival/(.*)$ /$1 break;
proxy_pass http://archival-api:80;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location ^~ /api/directory/ {
rewrite ^/api/directory/(.*)$ /$1 break;
proxy_pass http://directory-api:80;

View file

@ -9,6 +9,18 @@ server {
add_header Content-Security-Policy "default-src 'none'; connect-src 'self'; img-src 'self' validator.swagger.io data:; manifest-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; base-uri 'none'; form-action 'none'; frame-ancestors 'none';" always;
location ^~ /api/archival/ {
rewrite ^/api/archival/(.*)$ /$1 break;
proxy_pass http://archival-api:80;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location ^~ /api/directory/ {
rewrite ^/api/directory/(.*)$ /$1 break;
proxy_pass http://directory-api:80;

View file

@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace FilterLists.Archival.Api.Controllers
{
[ApiController]
[Route("[controller]")]
[Produces("application/json")]
public class PingController : ControllerBase
{
[HttpGet]
[ProducesResponseType(typeof(string), StatusCodes.Status200OK)]
#pragma warning disable CA1822 // Mark members as static
public ActionResult<string> Ping()
#pragma warning restore CA1822 // Mark members as static
{
return "pong";
}
}
}

View file

@ -24,6 +24,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.9" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="5.6.3" />
</ItemGroup>
<ItemGroup>

View file

@ -18,6 +18,10 @@ public Startup(IConfiguration configuration)
public void ConfigureServices(IServiceCollection services)
{
services.AddRouting(o => o.LowercaseUrls = true);
services.AddControllers()
.AddJsonOptions(o => o.JsonSerializerOptions.IgnoreNullValues = true);
services.AddSwaggerGen();
services.AddApplicationServices(Configuration);
}
@ -28,6 +32,10 @@ public static void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseEndpoints(e => e.MapControllers());
app.UseSwagger();
}
}
}

View file

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
namespace FilterLists.Archival.Api
{
internal static class SwaggerExtensions
{
public static void AddSwaggerGen(this IServiceCollection services)
{
services.AddSwaggerGen(o =>
{
o.SwaggerDoc("v1", new OpenApiInfo
{
Title = "FilterLists Archival API",
Description =
"FilterLists is the independent, comprehensive directory of filter and host lists for advertisements, trackers, malware, and annoyances.",
Version = "v1",
//TermsOfService = "",
Contact = new OpenApiContact {Name = "FilterLists", Url = new Uri("https://filterlists.com")},
License = new OpenApiLicense
{
Name = "MIT License",
Url = new Uri("https://github.com/collinbarrett/FilterLists/blob/master/LICENSE")
}
});
});
}
public static void UseSwagger(this IApplicationBuilder app)
{
app.UseSwagger(o =>
{
o.RouteTemplate = "{documentName}/swagger.json";
o.PreSerializeFilters.Add((swaggerDoc, httpReq) => swaggerDoc.Servers = new List<OpenApiServer>
{
#if DEBUG
new OpenApiServer {Url = $"{httpReq.Scheme}://{httpReq.Host.Value}:8080/api/archival"}
#else
new OpenApiServer {Url = $"https://{httpReq.Host.Value}/api/archival"}
#endif
});
});
}
}
}

View file

@ -26,7 +26,6 @@ public static void AddSwaggerGen(this IServiceCollection services)
Url = new Uri("https://github.com/collinbarrett/FilterLists/blob/master/LICENSE")
}
});
o.CustomSchemaIds(type => type.ToString());
});
}
@ -38,7 +37,7 @@ public static void UseSwagger(this IApplicationBuilder app)
o.PreSerializeFilters.Add((swaggerDoc, httpReq) => swaggerDoc.Servers = new List<OpenApiServer>
{
#if DEBUG
new OpenApiServer {Url = $"{httpReq.Scheme}://{httpReq.Host.Value}/api/directory"}
new OpenApiServer {Url = $"{httpReq.Scheme}://{httpReq.Host.Value}:8080/api/directory"}
#else
new OpenApiServer {Url = $"https://{httpReq.Host.Value}/api/directory"}
#endif