97 lines
3.3 KiB
C#
97 lines
3.3 KiB
C#
using System.IO;
|
|
using System.Text.Json.Serialization;
|
|
using Flexitime.DataAccess;
|
|
using Flexitime.Interfaces;
|
|
using FlexitimeAPI.Functions;
|
|
using FlexitimeAPI.Helpers;
|
|
using FlexitimeAPI.Interfaces;
|
|
using FlexitimeAPI.Models;
|
|
using FlexitimeAPI.Services;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.OpenApi.Models;
|
|
|
|
namespace FlexitimeAPI
|
|
{
|
|
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)
|
|
{
|
|
var settings = InitialiseAppSettings();
|
|
|
|
services.AddSingleton(typeof(IApplicationSettings), settings);
|
|
services.AddSingleton<ILoginService, LoginService>();
|
|
services.AddSingleton<IConnectionStringProvider, ConnectionStringProvider>();
|
|
services.AddSingleton<IDataAccess, Database>();
|
|
services.AddSingleton<IUserService, UserService>();
|
|
|
|
services.AddCors(options =>
|
|
{
|
|
options.AddDefaultPolicy(
|
|
builder =>
|
|
{
|
|
builder
|
|
.WithOrigins("http://localhost:3000")
|
|
.AllowAnyMethod()
|
|
.AllowAnyHeader();
|
|
});
|
|
});
|
|
|
|
services.AddControllers().AddJsonOptions(opts =>
|
|
{
|
|
opts.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
|
|
opts.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
|
|
});
|
|
|
|
services.AddSwaggerGen(c =>
|
|
{
|
|
c.SwaggerDoc("v1", new OpenApiInfo {Title = "FlexitimeAPI", Version = "v1"});
|
|
});
|
|
}
|
|
|
|
private IApplicationSettings InitialiseAppSettings()
|
|
{
|
|
var appSettings= new ConfigurationBuilder()
|
|
.SetBasePath(Directory.GetCurrentDirectory())
|
|
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
|
.Build()
|
|
.GetSection("Settings")
|
|
.Get<AppSettings>();
|
|
|
|
appSettings.Verify<AppSettings>();
|
|
|
|
return appSettings;
|
|
}
|
|
|
|
// 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.UseSwagger();
|
|
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "FlexitimeAPI v1"));
|
|
}
|
|
|
|
app.UseCors();
|
|
//app.UseHttpsRedirection();
|
|
app.UseRouting();
|
|
|
|
app.UseMiddleware<JwtMiddleware>();
|
|
app.UseAuthorization();
|
|
|
|
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
|
|
}
|
|
}
|
|
} |