HostRunArg.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using Microsoft.AspNetCore.Builder;
  3. using Microsoft.AspNetCore.Hosting;
  4. using Microsoft.Extensions.DependencyInjection;
  5. using Newtonsoft.Json;
  6. using Vit.WebHost.Extensions.UseCertificates;
  7. namespace Vit.WebHost
  8. {
  9. [JsonObject(MemberSerialization.OptIn)]
  10. public partial class HostRunArg
  11. {
  12. public Func<IWebHostBuilder> OnCreateWebHostBuilder = () => new WebHostBuilder().UseKestrel();
  13. /// <summary>
  14. ///
  15. /// </summary>
  16. [JsonProperty]
  17. public string[] urls;
  18. /// <summary>
  19. ///
  20. /// </summary>
  21. [JsonProperty]
  22. public CertificateInfo[] certificates;
  23. /// <summary>
  24. /// 是否允许跨域访问,默认true
  25. /// </summary>
  26. [JsonProperty]
  27. public bool allowAnyOrigin = true;
  28. /// <summary>
  29. /// 映射静态文件,可不指定
  30. /// </summary>
  31. [JsonProperty]
  32. public StaticFilesConfig staticFiles;
  33. /// <summary>
  34. /// 是否异步运行.Runs a web application and returns a Task that only completes when the token is triggered or shutdown is triggered.
  35. /// </summary>
  36. public bool RunAsync = false;
  37. public Action<IServiceCollection> OnConfigureServices = null;
  38. public Action<IApplicationBuilder> OnConfigure = null;
  39. public HostRunArg SetPort(int port = 8888)
  40. {
  41. urls = new string[] { "http://*:" + port };
  42. return this;
  43. }
  44. }
  45. }