chore(api): remove unused code

This commit is contained in:
spiral
2022-11-18 03:35:56 +00:00
parent b95f51fff4
commit 12d267ed1f
6 changed files with 641 additions and 652 deletions

View File

@@ -1,8 +0,0 @@
using Autofac;
namespace PluralKit.API;
public class APIModule: Module
{
protected override void Load(ContainerBuilder builder) { }
}

View File

@@ -28,21 +28,12 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="App.Metrics.AspNetCore.All" Version="4.3.0" />
<PackageReference Include="App.Metrics.Prometheus" Version="4.3.0" />
<PackageReference Include="App.Metrics.Reporting.Console" Version="4.3.0" />
<PackageReference Include="Google.Protobuf" Version="3.13.0" />
<PackageReference Include="Grpc.Tools" Version="2.47.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="4.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="4.2.0" />
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.6.3" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="6.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="5.6.3" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="5.6.3" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="5.6.3" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.6.3" />
</ItemGroup>
<ItemGroup>

View File

@@ -1,7 +1,3 @@
using App.Metrics;
using App.Metrics.AspNetCore;
using App.Metrics.Formatters.Prometheus;
using Autofac.Extensions.DependencyInjection;
using PluralKit.Core;
@@ -12,15 +8,8 @@ namespace PluralKit.API;
public class Program
{
public static IMetricsRoot _metrics { get; set; }
public static async Task Main(string[] args)
{
_metrics = AppMetrics.CreateDefaultBuilder()
.OutputMetrics.AsPrometheusPlainText()
.OutputMetrics.AsPrometheusProtobuf()
.Build();
InitUtils.InitStatic();
await BuildInfoService.LoadVersion();
var host = CreateHostBuilder(args).Build();
@@ -31,18 +20,6 @@ public class Program
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureMetrics(_metrics)
.UseMetricsWebTracking()
.UseMetricsEndpoints()
.UseMetrics(
options =>
{
options.EndpointOptions = endpointsOptions =>
{
endpointsOptions.MetricsTextEndpointOutputFormatter = _metrics.OutputMetricsFormatters.OfType<MetricsPrometheusTextOutputFormatter>().First();
endpointsOptions.MetricsEndpointOutputFormatter = _metrics.OutputMetricsFormatters.OfType<MetricsPrometheusProtobufOutputFormatter>().First();
};
})
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.UseSerilog()
.ConfigureWebHostDefaults(whb => whb

View File

@@ -17,17 +17,9 @@ namespace PluralKit.API;
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddCors();
services.AddControllers()
// sorry MS, this just does *more*
.AddNewtonsoftJson(opts =>
@@ -39,33 +31,6 @@ public class Startup
options.InvalidModelStateResponseFactory = context =>
throw Errors.GenericBadRequest
);
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1.0", new OpenApiInfo { Title = "PluralKit", Version = "1.0" });
c.EnableAnnotations();
c.AddSecurityDefinition("TokenAuth",
new OpenApiSecurityScheme { Name = "Authorization", Type = SecuritySchemeType.ApiKey });
// Exclude routes without a version, then fall back to group name matching (default behavior)
c.DocInclusionPredicate((docName, apiDesc) =>
{
if (!apiDesc.RelativePath.StartsWith("v1/")) return false;
return apiDesc.GroupName == docName;
});
// Set the comments path for the Swagger JSON and UI.
// https://docs.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-3.1&tabs=visual-studio#customize-and-extend
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
});
services.AddSwaggerGenNewtonsoftSupport();
// metrics
services.AddMetricsTrackingMiddleware();
services.AddAppMetricsCollectors();
}
public void ConfigureContainer(ContainerBuilder builder)
@@ -77,23 +42,13 @@ public class Startup
cfg: new LoggerConfiguration().Filter.ByExcluding(
exc => exc.Exception is PKError || exc.Exception.IsUserError()
)));
// builder.RegisterModule(new MetricsModule("API"));
builder.RegisterModule<DataStoreModule>();
builder.RegisterModule<APIModule>();
builder.RegisterModule(new MetricsModule());
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
// Only enable Swagger stuff when ASPNETCORE_ENVIRONMENT=Development (for now)
app.UseSwagger();
app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1.0/swagger.json", "PluralKit (v1)"); });
}
// add X-PluralKit-Version header
app.Use((ctx, next) =>
{
@@ -127,12 +82,7 @@ public class Startup
app.UseMiddleware<AuthorizationTokenHandlerMiddleware>();
//app.UseHttpsRedirection();
// app.UseCors(opts => opts.AllowAnyMethod().AllowAnyOrigin().WithHeaders("Content-Type", "Authorization", "sentry-trace"));
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
// register base / legacy routes
@@ -142,8 +92,5 @@ public class Startup
// register controllers
endpoints.MapControllers();
});
// metrics
app.UseMetricsAllMiddleware();
}
}

File diff suppressed because it is too large Load Diff