2020-02-15 16:00:42 +03:00
|
|
|
using Microsoft.AspNetCore.Builder;
|
2021-01-24 18:16:15 +01:00
|
|
|
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
2020-02-15 16:00:42 +03:00
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2021-01-24 18:16:15 +01:00
|
|
|
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
2020-05-23 11:43:14 +02:00
|
|
|
using WotBlitzStatisticsPro.Common;
|
2020-05-18 17:29:54 +02:00
|
|
|
using WotBlitzStatisticsPro.Common.Model;
|
2020-05-23 11:43:14 +02:00
|
|
|
using WotBlitzStatisticsPro.GraphQl.Mutation;
|
|
|
|
|
using WotBlitzStatisticsPro.GraphQl.ObjectTypes;
|
|
|
|
|
using WotBlitzStatisticsPro.GraphQl.Query;
|
|
|
|
|
using WotBlitzStatisticsPro.Logic;
|
2020-02-15 16:00:42 +03:00
|
|
|
|
2020-05-23 11:43:14 +02:00
|
|
|
namespace WotBlitzStatisticsPro.GraphQl
|
2020-02-15 16:00:42 +03:00
|
|
|
{
|
|
|
|
|
public class Startup
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public Startup(IConfiguration configuration)
|
|
|
|
|
{
|
|
|
|
|
Configuration = configuration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IConfiguration Configuration { get; }
|
|
|
|
|
|
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
var wgApiConfig = new WargamingApiSettings();
|
|
|
|
|
Configuration.GetSection("WargamingApi").Bind(wgApiConfig);
|
|
|
|
|
|
2020-05-31 15:43:39 +02:00
|
|
|
var mongoConfig = new MongoSettings();
|
|
|
|
|
Configuration.GetSection("Mongo").Bind(mongoConfig);
|
|
|
|
|
|
2020-02-15 16:00:42 +03:00
|
|
|
services.AddSingleton<IWargamingApiSettings>(wgApiConfig);
|
2020-05-31 15:43:39 +02:00
|
|
|
services.AddSingleton<IMongoSettings>(mongoConfig);
|
2020-05-18 17:29:54 +02:00
|
|
|
WotBlitzStatisticsLogicInstaller.ConfigureServices(services);
|
2020-02-15 16:00:42 +03:00
|
|
|
|
2021-01-24 18:16:15 +01:00
|
|
|
services.AddHealthChecks()
|
|
|
|
|
.AddCheck("self", () => HealthCheckResult.Healthy())
|
|
|
|
|
.AddMongoDb(mongoConfig.ConnectionString, tags: new[] { "services" });
|
2020-03-12 19:44:41 +01:00
|
|
|
|
2020-02-15 16:00:42 +03:00
|
|
|
// Add GraphQL Services
|
2021-01-24 18:16:15 +01:00
|
|
|
services.AddGraphQLServer()
|
2020-12-23 17:30:16 +01:00
|
|
|
.AddQueryType<WotBlitzStatisticsQuery>()
|
2020-05-21 17:53:01 +02:00
|
|
|
.AddMutationType<WotBlitzStatisticsMutation>()
|
2020-12-23 17:30:16 +01:00
|
|
|
.AddType<AccountsSearchItemObjectType>()
|
|
|
|
|
.AddType<AccountsSearchObjectType>()
|
|
|
|
|
.AddEnumType<MarkOfMastery>()
|
|
|
|
|
.AddEnumType<RealmType>()
|
|
|
|
|
.AddEnumType<RequestLanguage>();
|
|
|
|
|
|
2020-02-15 16:00:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
|
|
|
{
|
|
|
|
|
app
|
2020-12-23 17:30:16 +01:00
|
|
|
.UseRouting()
|
|
|
|
|
.UseEndpoints(endpoints =>
|
|
|
|
|
{
|
|
|
|
|
endpoints.MapGraphQL();
|
2021-01-24 18:16:15 +01:00
|
|
|
endpoints.MapHealthChecks("/health/self", new HealthCheckOptions
|
|
|
|
|
{
|
|
|
|
|
Predicate = r => r.Tags.Contains("self")
|
|
|
|
|
});
|
|
|
|
|
endpoints.MapHealthChecks("/health/startup", new HealthCheckOptions
|
|
|
|
|
{
|
|
|
|
|
Predicate = r => r.Tags.Contains("services")
|
|
|
|
|
});
|
|
|
|
|
});
|
2020-02-15 16:00:42 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|