-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94b45f1
commit ace5077
Showing
4 changed files
with
112 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,78 @@ | ||
using ClassifiedAds.Infrastructure.Logging; | ||
using ClassifiedAds.GraphQL; | ||
using ClassifiedAds.Infrastructure.HealthChecks; | ||
using ClassifiedAds.Infrastructure.HostedServices; | ||
using ClassifiedAds.Infrastructure.Logging; | ||
using GraphQL; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Diagnostics.HealthChecks; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Server.Kestrel.Core; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using System; | ||
|
||
namespace ClassifiedAds.GraphQL; | ||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add services to the container. | ||
var services = builder.Services; | ||
var configuration = builder.Configuration; | ||
// Add services to the container. | ||
var services = builder.Services; | ||
var configuration = builder.Configuration; | ||
|
||
builder.WebHost.UseClassifiedAdsLogger(configuration => | ||
builder.WebHost.UseClassifiedAdsLogger(configuration => | ||
{ | ||
return new LoggingOptions(); | ||
}); | ||
|
||
// If using Kestrel: | ||
services.Configure<KestrelServerOptions>(options => | ||
{ | ||
options.AllowSynchronousIO = true; | ||
}); | ||
|
||
// If using IIS: | ||
services.Configure<IISServerOptions>(options => | ||
{ | ||
options.AllowSynchronousIO = true; | ||
}); | ||
// If using Kestrel: | ||
services.Configure<KestrelServerOptions>(options => | ||
{ | ||
options.AllowSynchronousIO = true; | ||
}); | ||
|
||
services.AddLogging(builder => builder.AddConsole()); | ||
services.AddHttpContextAccessor(); | ||
// If using IIS: | ||
services.Configure<IISServerOptions>(options => | ||
{ | ||
options.AllowSynchronousIO = true; | ||
}); | ||
|
||
services.AddGraphQL(b => b.AddAutoSchema<ClassifiedAdsQuery>(s => s.WithMutation<ClassifiedAdsMutation>()) | ||
.AddSystemTextJson()); | ||
services.AddLogging(builder => builder.AddConsole()); | ||
services.AddHttpContextAccessor(); | ||
|
||
// Configure the HTTP request pipeline. | ||
var app = builder.Build(); | ||
services.AddGraphQL(b => b.AddAutoSchema<ClassifiedAdsQuery>(s => s.WithMutation<ClassifiedAdsMutation>()) | ||
.AddSystemTextJson()); | ||
|
||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
services.AddHealthChecks() | ||
.AddHttp(configuration["ResourceServer:Endpoint"], name: "Resource (Web API) Server", failureStatus: HealthStatus.Degraded); | ||
|
||
// add http for Schema at default url /graphql | ||
app.UseGraphQL(); | ||
services.Configure<HealthChecksBackgroundServiceOptions>(x => x.Interval = TimeSpan.FromMinutes(10)); | ||
services.AddHostedService<HealthChecksBackgroundService>(); | ||
|
||
// use graphql-playground at default url /ui/playground | ||
app.UseGraphQLPlayground(); | ||
// Configure the HTTP request pipeline. | ||
var app = builder.Build(); | ||
|
||
app.Run(); | ||
} | ||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
|
||
app.UseHealthChecks("/healthz", new HealthCheckOptions | ||
{ | ||
Predicate = _ => true, | ||
ResponseWriter = HealthChecksResponseWriter.WriteReponse, | ||
ResultStatusCodes = | ||
{ | ||
[HealthStatus.Healthy] = StatusCodes.Status200OK, | ||
[HealthStatus.Degraded] = StatusCodes.Status500InternalServerError, | ||
[HealthStatus.Unhealthy] = StatusCodes.Status503ServiceUnavailable, | ||
}, | ||
}); | ||
|
||
// add http for Schema at default url /graphql | ||
app.UseGraphQL(); | ||
|
||
// use graphql-playground at default url /ui/playground | ||
app.UseGraphQLPlayground(); | ||
|
||
app.Run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters