HostRunArg.cs 1.4 KB

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