Skip to content

Instantly share code, notes, and snippets.

@scionwest
Created January 13, 2017 06:50
Show Gist options
  • Save scionwest/adf5f7630d2661b6da896d4075374f84 to your computer and use it in GitHub Desktop.
Save scionwest/adf5f7630d2661b6da896d4075374f84 to your computer and use it in GitHub Desktop.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
this.ServiceProvider = app.ApplicationServices;
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseOAuthValidation();
app.UseOpenIddict();
app.Map("/api", apiApp =>
{
if (env.IsDevelopment())
{
apiApp.UseCors(builder =>
builder.WithOrigins("http://localhost:4200")
.AllowAnyHeader()
.AllowAnyMethod()
);
}
apiApp.UseOAuthValidation(options =>
{
options.Events = new OAuthValidationEvents
{
// Note: for SignalR connections, the default Authorization header does not work,
// because the WebSockets JS API doesn't allow setting custom parameters.
// To work around this limitation, the access token is retrieved from the query string.
OnRetrieveToken = context =>
{
context.Token = context.Request.Query["access_token"];
return Task.FromResult(0);
}
};
});
//apiApp.UseSignalR(router =>
//{
// router.MapHub<ExamHub>("/exam-hub");
//});
//apiApp.UseSignalR2();
apiApp.UseOpenIddict();
apiApp.UseMvc(routes =>
{
// Matches requests that correspond to an existent controller/action pair
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}");
});
});
app.Use(async (context, next) =>
{
await next();
if (context.Response.StatusCode == 404
&& !Path.HasExtension(context.Request.Path.Value))
{
context.Request.Path = "/index.html";
await next();
}
});
app.UseStaticFiles();
app.UseDefaultFiles();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment