initial
This commit is contained in:
53
src/API/Program.cs
Normal file
53
src/API/Program.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using API.Extension;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddWebServices();
|
||||
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("AllowLocalhost",
|
||||
policy =>
|
||||
{
|
||||
policy.WithOrigins("http://localhost:44492")
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod();
|
||||
});
|
||||
});
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment() || app.Environment.IsEnvironment("Test"))
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseCors("AllowLocalhost");
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
app.MapControllers();
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.Run();
|
||||
|
||||
public class LowerCaseDocumentFilter : IDocumentFilter
|
||||
{
|
||||
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
|
||||
{
|
||||
// get the paths
|
||||
var paths = swaggerDoc.Paths.ToDictionary(
|
||||
path => path.Key.ToLowerInvariant(),
|
||||
path => swaggerDoc.Paths[path.Key]);
|
||||
|
||||
// add the paths
|
||||
swaggerDoc.Paths = new OpenApiPaths();
|
||||
foreach (var pathItem in paths) swaggerDoc.Paths.Add(pathItem.Key, pathItem.Value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user