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

  1. using Microsoft.Extensions.FileProviders;
  2. using Microsoft.Extensions.Options;
  3. using NLog.Web;
  4. var builder = WebApplication.CreateBuilder(args);
  5. var configuration = builder.Configuration;
  6. // Add services to the container.
  7. //nlog
  8. builder.Logging.AddNLog("Configs/NLog.config");
  9. builder.Services.AddControllers();
  10. // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
  11. builder.Services.AddEndpointsApiExplorer();
  12. builder.Services.AddSwaggerGen(opt =>
  13. {
  14. var baseDirectory = AppContext.BaseDirectory;
  15. var commentsFile = Path.Combine(baseDirectory, "Shentun.PeisReport.Api.xml");
  16. opt.IncludeXmlComments(commentsFile, true);
  17. });
  18. builder.Services.AddCors(options =>
  19. {
  20. options.AddPolicy("AllowAll",
  21. builder => builder
  22. .AllowAnyOrigin()
  23. .AllowAnyMethod()
  24. .AllowAnyHeader());
  25. });
  26. var app = builder.Build();
  27. var isSwagger = Convert.ToBoolean(configuration["Swagger:IsEnabled"]);
  28. if (isSwagger)
  29. {
  30. app.UseSwagger();
  31. app.UseSwaggerUI();
  32. }
  33. //����Ŀ¼
  34. app.UseStaticFiles(new StaticFileOptions
  35. {
  36. FileProvider = new PhysicalFileProvider(configuration["ReportVirtualPath:RealPath"]),
  37. RequestPath = configuration["ReportVirtualPath:RequestPath"]
  38. });
  39. app.UseCors("AllowAll");
  40. app.UseAuthorization();
  41. app.MapControllers();
  42. app.Run();