124 lines
4.5 KiB
C#
124 lines
4.5 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using System.Text.Json.Serialization;
|
|
using BlueWest.Tools;
|
|
using BlueWest.WebApi.Interfaces;
|
|
using BlueWest.WebApi.Tools;
|
|
using Microsoft.OpenApi.Models;
|
|
|
|
namespace BlueWest.WebApi
|
|
{
|
|
/// <summary>
|
|
/// Startup class for the API.
|
|
/// </summary>
|
|
public class Startup
|
|
{
|
|
private readonly IConfiguration _configuration;
|
|
private readonly IWebHostEnvironment _environment;
|
|
private readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
|
|
|
|
/// <summary>
|
|
/// Startup configuration of the API
|
|
/// </summary>
|
|
public Startup(IConfiguration configuration, IWebHostEnvironment hostEnvironment)
|
|
{
|
|
_configuration = configuration;
|
|
_environment = hostEnvironment;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Configure Services
|
|
/// </summary>
|
|
/// <param name="services">Dependency injection</param>
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddCors(options =>
|
|
{
|
|
/*options.AddPolicy(name: MyAllowSpecificOrigins,
|
|
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();
|
|
});*/
|
|
});
|
|
|
|
services
|
|
.AddControllers()
|
|
.AddJsonOptions(options => options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.Preserve);
|
|
|
|
services
|
|
.AddSwaggerGen(options =>
|
|
{
|
|
options.SchemaFilter<SwaggerEnumSchemaFilter>();
|
|
options.SwaggerDoc("v1", new OpenApiInfo
|
|
{
|
|
Title = "BlueWest.Api.App",
|
|
Version = "v1",
|
|
Description = "BlueWest.Api.App",
|
|
TermsOfService = new Uri("https://git.codeliturgy.com/terms-of-service"),
|
|
Contact = new OpenApiContact
|
|
{
|
|
Name = "Benny",
|
|
Email = string.Empty,
|
|
Url = new Uri("https://git.codeliturgy.com"),
|
|
},
|
|
License = new OpenApiLicense
|
|
{
|
|
Name = "Use under LICX",
|
|
Url = new Uri("https://git.codeliturgy.com/license"),
|
|
}
|
|
});
|
|
|
|
// Set the comments path for the Swagger JSON and UI.
|
|
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
|
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
|
options.IncludeXmlComments(xmlPath);
|
|
});
|
|
services
|
|
.AddSingleton<EventManager>()
|
|
.PrepareDatabasePool(_configuration, _environment)
|
|
.AddScoped<ExchangeInterface>();
|
|
|
|
// services.AddGrpc();
|
|
}
|
|
|
|
|
|
/// <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>
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
{
|
|
|
|
//app.UseStaticFiles();
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI(c =>
|
|
{
|
|
c.RoutePrefix = "swagger";
|
|
c.SwaggerEndpoint("/swagger/v1/swagger.json", "BlueWest.Api v1");
|
|
});
|
|
|
|
//app.UseHttpsRedirection();
|
|
|
|
app.UseRouting();
|
|
app.UseCors(MyAllowSpecificOrigins);
|
|
app.UseAuthorization();
|
|
app.UseEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapControllers();
|
|
// endpoints.MapGrpcService<GreeterService>();
|
|
});
|
|
}
|
|
}
|
|
}
|