HostRunArg.cs 1.9 KB

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