2021-12-06 02:49:27 +03:00
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2022-08-19 02:02:57 +03:00
|
|
|
using System.Text.Json.Serialization;
|
2022-08-19 19:47:35 +03:00
|
|
|
using BlueWest.Tools;
|
2022-08-20 05:47:32 +03:00
|
|
|
using BlueWest.WebApi.Extensions;
|
2022-08-19 19:47:35 +03:00
|
|
|
using BlueWest.WebApi.Interfaces;
|
2021-12-06 02:49:27 +03:00
|
|
|
|
|
|
|
namespace BlueWest.WebApi
|
|
|
|
{
|
2022-08-20 05:47:32 +03:00
|
|
|
/// <summary>
|
|
|
|
/// Startup class for the API.
|
|
|
|
/// </summary>
|
2021-12-06 02:49:27 +03:00
|
|
|
public class Startup
|
|
|
|
{
|
2022-08-20 05:47:32 +03:00
|
|
|
private readonly IConfiguration _configuration;
|
2022-08-19 19:47:35 +03:00
|
|
|
private readonly IWebHostEnvironment _environment;
|
|
|
|
private readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
|
|
|
|
|
2022-08-19 02:20:06 +03:00
|
|
|
/// <summary>
|
|
|
|
/// Startup configuration of the API
|
|
|
|
/// </summary>
|
2022-08-19 19:47:35 +03:00
|
|
|
public Startup(IConfiguration configuration, IWebHostEnvironment hostEnvironment)
|
2021-12-06 02:49:27 +03:00
|
|
|
{
|
2022-08-20 05:47:32 +03:00
|
|
|
_configuration = configuration;
|
2022-08-19 19:47:35 +03:00
|
|
|
_environment = hostEnvironment;
|
2021-12-06 02:49:27 +03:00
|
|
|
}
|
2022-08-19 19:47:35 +03:00
|
|
|
|
2021-12-06 02:49:27 +03:00
|
|
|
|
2022-08-19 19:47:35 +03:00
|
|
|
/// <summary>
|
|
|
|
/// Configure Services
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="services">Dependency injection</param>
|
2021-12-06 02:49:27 +03:00
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
{
|
|
|
|
services.AddCors(options =>
|
|
|
|
{
|
2022-08-13 08:34:20 +03:00
|
|
|
/*options.AddPolicy(name: MyAllowSpecificOrigins,
|
2021-12-06 02:49:27 +03:00
|
|
|
builder =>
|
|
|
|
{
|
|
|
|
builder.WithOrigins("http://localhost", "http://127.0.0.1", "http://localhost:3000",
|
|
|
|
"http://127.0.0.1:3000", "localhost:3000", "127.0.0.1:3000")
|
|
|
|
.AllowAnyHeader().AllowAnyMethod();
|
2022-08-13 08:34:20 +03:00
|
|
|
});*/
|
2021-12-06 02:49:27 +03:00
|
|
|
});
|
|
|
|
|
2022-08-20 05:47:32 +03:00
|
|
|
services
|
|
|
|
.AddControllers()
|
|
|
|
.AddJsonOptions(options => options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.Preserve);
|
2022-08-19 06:18:50 +03:00
|
|
|
|
2022-08-20 05:47:32 +03:00
|
|
|
services
|
|
|
|
.AddSwaggerGen(options => options.ConfigureSwaggerOptions());
|
2022-08-19 06:18:50 +03:00
|
|
|
services
|
2022-08-19 19:47:35 +03:00
|
|
|
.AddSingleton<EventManager>()
|
2022-08-20 05:47:32 +03:00
|
|
|
.PrepareDatabasePool(_configuration, _environment)
|
|
|
|
.AddScoped<ExchangeInterface>();
|
2022-08-19 19:47:35 +03:00
|
|
|
|
2022-08-13 08:34:20 +03:00
|
|
|
// services.AddGrpc();
|
2021-12-06 02:49:27 +03:00
|
|
|
}
|
2022-08-13 06:35:36 +03:00
|
|
|
|
|
|
|
|
2022-08-20 05:47:32 +03:00
|
|
|
/// <summary>
|
|
|
|
/// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="app">Object with the necessary data to configure an application's request pipeline</param>
|
|
|
|
/// <param name="env">Provides information about the web hosting environment an application is running in.</param>
|
2021-12-06 02:49:27 +03:00
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
|
|
{
|
2022-08-13 20:15:43 +03:00
|
|
|
|
|
|
|
//app.UseStaticFiles();
|
|
|
|
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
app.UseSwagger();
|
|
|
|
app.UseSwaggerUI(c =>
|
2021-12-06 02:49:27 +03:00
|
|
|
{
|
2022-08-13 20:15:43 +03:00
|
|
|
c.RoutePrefix = "swagger";
|
|
|
|
c.SwaggerEndpoint("/swagger/v1/swagger.json", "BlueWest.Api v1");
|
|
|
|
});
|
2021-12-06 02:49:27 +03:00
|
|
|
|
2022-08-13 18:21:23 +03:00
|
|
|
//app.UseHttpsRedirection();
|
2021-12-06 02:49:27 +03:00
|
|
|
|
|
|
|
app.UseRouting();
|
|
|
|
app.UseCors(MyAllowSpecificOrigins);
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
|
|
{
|
|
|
|
endpoints.MapControllers();
|
2022-08-13 08:34:20 +03:00
|
|
|
// endpoints.MapGrpcService<GreeterService>();
|
2021-12-06 02:49:27 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|