Skip to content

Commit

Permalink
handle cors
Browse files Browse the repository at this point in the history
  • Loading branch information
runeanielsen committed Aug 21, 2020
1 parent 2400576 commit e5d1ab9
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion OpenFTTH.APIGateway/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace OpenFTTH.APIGateway
{
public class Startup
{
readonly string AllowedOrigins = "_myAllowSpecificOrigins";

public Startup(IConfiguration configuration)
{
Configuration = configuration;
Expand Down Expand Up @@ -68,14 +70,26 @@ public void ConfigureServices(IServiceCollection services)
// Web stuff
services.AddRazorPages();

// CORS
services.AddCors(options =>
{
options.AddPolicy(name: AllowedOrigins,
builder =>
{
builder.AllowAnyOrigin();
builder.AllowAnyMethod();
builder.AllowAnyHeader();
});
});

// Services used by the API gateways
services.AddHostedService<RouteNetworkEventConsumer>();
services.AddSingleton<IToposTypedEventObservable<RouteNetworkEvent>, ToposTypedEventObservable<RouteNetworkEvent>>();


services.AddSingleton<QueryServiceClient<RouteNetworkServiceQueries>>(x =>
new QueryServiceClient<RouteNetworkServiceQueries>(
x.GetRequiredService<Microsoft.Extensions.Logging.ILogger<QueryServiceClient<RouteNetworkServiceQueries>>>(),
x.GetRequiredService<Microsoft.Extensions.Logging.ILogger<QueryServiceClient<RouteNetworkServiceQueries>>>(),
Configuration.GetSection("RemoteServices:RouteNetworkService").Value)
);

Expand Down Expand Up @@ -105,6 +119,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseExceptionHandler("/Error");
}

app.UseCors(AllowedOrigins);

app.UseWebSockets();
app.UseGraphQLWebSockets<OpenFTTHSchema>("/graphql");
app.UseGraphQL<OpenFTTHSchema>("/graphql");
Expand Down

0 comments on commit e5d1ab9

Please sign in to comment.