133 lines
4.7 KiB
C#
133 lines
4.7 KiB
C#
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.HttpsPolicy;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text.Json.Serialization;
|
|
using System.Threading.Tasks;
|
|
using BlueWest.WebApi.MySQL;
|
|
using BlueWest.WebApi.Tools;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.OpenApi.Models;
|
|
|
|
namespace BlueWest.WebApi
|
|
{
|
|
public class Startup
|
|
{
|
|
public Startup(IConfiguration configuration)
|
|
{
|
|
Configuration = configuration;
|
|
}
|
|
readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
|
|
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.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
|
|
.AddNewtonsoftJson(options =>
|
|
options.SerializerSettings.Converters.Add(new StringEnumConverter()));
|
|
// order is vital, this *must* be called *after* AddNewtonsoftJson()
|
|
services.AddSwaggerGenNewtonsoftSupport();*/
|
|
|
|
services.AddSwaggerGen(options =>
|
|
{
|
|
options.SchemaFilter<SwaggerEnumSchemaFilter>();
|
|
options.SwaggerDoc("v1", new OpenApiInfo
|
|
{
|
|
Title = "BlueWest.Api Documentation",
|
|
Version = "v1",
|
|
Description = "A simple example ASP.NET Core Web API",
|
|
TermsOfService = new Uri("https://example.com/terms"),
|
|
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.AddDbContextPool<UserDbContext>(options =>
|
|
options.GetSqlSettings(Configuration))
|
|
.AddDbContextPool<CountriesDbContext>(options =>
|
|
options.GetSqlSettings(Configuration))
|
|
.AddDbContextPool<FinanceDbContext>(options =>
|
|
options.GetSqlSettings(Configuration))
|
|
.AddDbContextPool<CountriesDbContext>(options =>
|
|
options.GetSqlSettings(Configuration));
|
|
|
|
|
|
|
|
// services.AddGrpc();
|
|
}
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
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>();
|
|
|
|
});
|
|
}
|
|
}
|
|
}
|