92 lines
2.9 KiB
C#
92 lines
2.9 KiB
C#
using KTUSAPS.Services;
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using System;
|
|
using VueCliMiddleware;
|
|
|
|
namespace KTUSAPS
|
|
{
|
|
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)
|
|
{
|
|
services.AddControllers();
|
|
services.AddSpaStaticFiles(configuration =>
|
|
{
|
|
configuration.RootPath = "ClientApp/dist";
|
|
});
|
|
|
|
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
|
.AddJwtBearer(options =>
|
|
{
|
|
options.Audience = "5931fda0-e9e0-4754-80c2-18bcb9d9561a";
|
|
options.Authority = "https://login.microsoftonline.com/3415f2f7-f5a8-4092-b52a-003aaf844853/v2.0";
|
|
});
|
|
|
|
services.AddAuthorization((configure) =>
|
|
{
|
|
configure.DefaultPolicy = new Microsoft.AspNetCore.Authorization.AuthorizationPolicyBuilder()
|
|
.RequireAuthenticatedUser()
|
|
.Build();
|
|
});
|
|
|
|
var connectionString = Configuration.GetConnectionString("Main");
|
|
services.AddDbContext<Data.SAPSDataContext>((options) => options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString)));
|
|
services.AddHostedService<DatabaseInitializationService>();
|
|
|
|
services.AddSwaggerGen();
|
|
}
|
|
|
|
// 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();
|
|
|
|
app.UseSwaggerUI(c =>
|
|
{
|
|
c.SwaggerEndpoint("/swagger/v1/swagger.json", "API");
|
|
});
|
|
}
|
|
|
|
app.UseSwagger(c =>
|
|
{
|
|
});
|
|
app.UseRouting();
|
|
app.UseSpaStaticFiles();
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapControllers();
|
|
});
|
|
|
|
app.UseSpa(spa =>
|
|
{
|
|
spa.Options.SourcePath = "ClientApp/";
|
|
|
|
if (env.IsDevelopment())
|
|
{
|
|
spa.UseVueCli(npmScript: "serve");
|
|
}
|
|
|
|
});
|
|
}
|
|
}
|
|
}
|