You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/projects/IoTDameon/Startup.cs

74 lines
2.4 KiB

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace IoTDameon
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
private readonly string _origins = "AllowAllHeaders";
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options => options.AddPolicy(_origins,
builder =>
{
builder.SetIsOriginAllowed(o => true).AllowAnyMethod().AllowAnyHeader().AllowCredentials();
})
);
services.AddSingleton<UpdateIoTNodeService>();
services.AddHostedService<UpdateIoTNodeService>(o => o.GetRequiredService<UpdateIoTNodeService>());
services.AddHttpClient();
services.AddSignalR(o => o.EnableDetailedErrors = true).AddJsonProtocol();
services.AddControllersWithViews();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
}
string basePath = this.Configuration.GetSection("AppSettings").GetValue<string>("BasePath");
if (!string.IsNullOrEmpty(basePath))
{
app.UsePathBase(basePath);
}
app.UseCors(_origins);
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<DefaultHub>("/hub", o =>
{
o.ApplicationMaxBufferSize = long.MaxValue;
o.TransportMaxBufferSize = long.MaxValue;
});
endpoints.MapControllerRoute(
name: "areas",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}