98 lines
2.6 KiB
C#
98 lines
2.6 KiB
C#
using Microsoft.Extensions.WebEncoders;
|
|
using Microsoft.OpenApi.Models;
|
|
using SwaggerFilter.Filters;
|
|
using System.Reflection;
|
|
using System.Text.Encodings.Web;
|
|
using System.Text.Unicode;
|
|
|
|
var log4netRepository = log4net.LogManager.GetRepository(Assembly.GetEntryAssembly());
|
|
log4net.Config.XmlConfigurator.Configure(log4netRepository, new FileInfo("log4net.config"));
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
var services = builder.Services;
|
|
|
|
// Add services to the container.
|
|
services.AddControllers();
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
services.AddEndpointsApiExplorer();
|
|
|
|
//HttpContext 사용
|
|
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
|
|
|
services.AddSwaggerGen(gen =>
|
|
{
|
|
gen.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo
|
|
{
|
|
Version = "v1",
|
|
Title = "KART API NET 8.0",
|
|
Description = "KART API NET 8.0"
|
|
});
|
|
|
|
gen.AddSecurityDefinition("token", new OpenApiSecurityScheme
|
|
{
|
|
Description = "Custom header for token",
|
|
Name = "token",
|
|
In = ParameterLocation.Header,
|
|
Type = SecuritySchemeType.ApiKey,
|
|
});
|
|
|
|
gen.AddSecurityRequirement(new OpenApiSecurityRequirement
|
|
{
|
|
{
|
|
new OpenApiSecurityScheme
|
|
{
|
|
Reference = new OpenApiReference
|
|
{
|
|
Type = ReferenceType.SecurityScheme,
|
|
Id = "token"
|
|
},
|
|
Name = "token",
|
|
In = ParameterLocation.Header,
|
|
},
|
|
new List<string>()
|
|
}
|
|
});
|
|
|
|
gen.DocumentFilter<CustomSwaggerFilter>();
|
|
gen.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
|
|
});
|
|
|
|
services.Configure<WebEncoderOptions>(options =>
|
|
{
|
|
options.TextEncoderSettings = new TextEncoderSettings(UnicodeRanges.All); // 한글이 인코딩되는 문제 해결
|
|
});
|
|
|
|
services.AddCors(options => {
|
|
options.AddDefaultPolicy(policy =>
|
|
{
|
|
policy.AllowAnyHeader()
|
|
.AllowAnyMethod()
|
|
.AllowAnyOrigin()
|
|
.WithExposedHeaders(new string[] { "Content-Disposition" });
|
|
});
|
|
});
|
|
|
|
//Server Path사용
|
|
AppDomain.CurrentDomain.SetData("ContentRootPath", Environment.CurrentDirectory);
|
|
|
|
var app = builder.Build();
|
|
app.UseCors();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (app.Environment.IsDevelopment() || app.Environment.IsProduction())
|
|
{
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI(c =>
|
|
{
|
|
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Showing API V1");
|
|
});
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllers();
|
|
|
|
app.Run();
|