2020-10-24 23:23:22 +02:00
|
|
|
using Birdmap.BLL;
|
|
|
|
using Birdmap.BLL.Interfaces;
|
|
|
|
using Birdmap.DAL;
|
2020-10-21 17:04:54 +02:00
|
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
2020-10-21 11:05:17 +02:00
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
using Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer;
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Microsoft.Extensions.Hosting;
|
2020-10-21 17:04:54 +02:00
|
|
|
using Microsoft.IdentityModel.Tokens;
|
|
|
|
using System.Text;
|
2020-10-21 11:05:17 +02:00
|
|
|
|
|
|
|
namespace Birdmap
|
|
|
|
{
|
|
|
|
public class Startup
|
|
|
|
{
|
|
|
|
public Startup(IConfiguration configuration)
|
|
|
|
{
|
|
|
|
Configuration = configuration;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IConfiguration Configuration { get; }
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
{
|
2020-10-21 17:04:54 +02:00
|
|
|
services.AddControllersWithViews()
|
|
|
|
.AddJsonOptions(opt =>
|
|
|
|
{
|
|
|
|
//opt.JsonSerializerOptions.PropertyNamingPolicy = new JsonNamingPolicy()
|
|
|
|
});
|
|
|
|
|
2020-10-24 23:23:22 +02:00
|
|
|
services.ConfigureBLL(Configuration);
|
|
|
|
services.ConfigureDAL(Configuration);
|
2020-10-21 17:04:54 +02:00
|
|
|
|
2020-10-24 23:23:22 +02:00
|
|
|
var key = Encoding.ASCII.GetBytes(Configuration["Secret"]);
|
2020-10-21 17:04:54 +02:00
|
|
|
services.AddAuthentication(opt =>
|
|
|
|
{
|
|
|
|
opt.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
|
|
opt.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
|
|
})
|
|
|
|
.AddJwtBearer(opt =>
|
|
|
|
{
|
|
|
|
// opt.RequireHttpsMetadata = false;
|
|
|
|
opt.SaveToken = true;
|
|
|
|
opt.IncludeErrorDetails = true;
|
|
|
|
opt.TokenValidationParameters = new TokenValidationParameters
|
|
|
|
{
|
|
|
|
ValidateIssuerSigningKey = true,
|
|
|
|
IssuerSigningKey = new SymmetricSecurityKey(key),
|
|
|
|
ValidateIssuer = false,
|
|
|
|
ValidateAudience = false
|
|
|
|
};
|
|
|
|
});
|
2020-10-21 11:05:17 +02:00
|
|
|
|
|
|
|
// In production, the React files will be served from this directory
|
|
|
|
services.AddSpaStaticFiles(configuration =>
|
|
|
|
{
|
|
|
|
configuration.RootPath = "ClientApp/build";
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
|
|
{
|
|
|
|
if (env.IsDevelopment())
|
|
|
|
{
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
app.UseExceptionHandler("/Error");
|
|
|
|
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
|
|
|
app.UseHsts();
|
|
|
|
}
|
|
|
|
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseStaticFiles();
|
|
|
|
app.UseSpaStaticFiles();
|
|
|
|
|
|
|
|
app.UseRouting();
|
|
|
|
|
2020-10-21 17:04:54 +02:00
|
|
|
app.UseAuthorization();
|
|
|
|
app.UseAuthentication();
|
|
|
|
|
2020-10-21 11:05:17 +02:00
|
|
|
app.UseEndpoints(endpoints =>
|
|
|
|
{
|
2020-10-21 17:04:54 +02:00
|
|
|
endpoints.MapControllers();
|
2020-10-21 11:05:17 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
app.UseSpa(spa =>
|
|
|
|
{
|
|
|
|
spa.Options.SourcePath = "ClientApp";
|
|
|
|
|
|
|
|
if (env.IsDevelopment())
|
|
|
|
{
|
|
|
|
spa.UseReactDevelopmentServer(npmScript: "start");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|