You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.3 KiB

using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Options;
using NLog.Web;
var builder = WebApplication.CreateBuilder(args);
var configuration = builder.Configuration;
// Add services to the container.
//nlog
builder.Logging.AddNLog("Configs/NLog.config");
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(opt =>
{
var baseDirectory = AppContext.BaseDirectory;
var commentsFile = Path.Combine(baseDirectory, "Shentun.PeisReport.Api.xml");
opt.IncludeXmlComments(commentsFile, true);
});
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAll",
builder => builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
});
var app = builder.Build();
var isSwagger = Convert.ToBoolean(configuration["Swagger:IsEnabled"]);
if (isSwagger)
{
app.UseSwagger();
app.UseSwaggerUI();
}
//ÐéÄâĿ¼
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(configuration["ReportVirtualPath:RealPath"]),
RequestPath = configuration["ReportVirtualPath:RequestPath"]
});
app.UseCors("AllowAll");
app.UseAuthorization();
app.MapControllers();
app.Run();