Startup.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using Jellyfin.Server.Extensions;
  2. using Jellyfin.Server.Middleware;
  3. using MediaBrowser.Controller;
  4. using MediaBrowser.Controller.Configuration;
  5. using Microsoft.AspNetCore.Builder;
  6. using Microsoft.AspNetCore.Hosting;
  7. using Microsoft.Extensions.DependencyInjection;
  8. using Microsoft.Extensions.Hosting;
  9. namespace Jellyfin.Server
  10. {
  11. /// <summary>
  12. /// Startup configuration for the Kestrel webhost.
  13. /// </summary>
  14. public class Startup
  15. {
  16. private readonly IServerConfigurationManager _serverConfigurationManager;
  17. /// <summary>
  18. /// Initializes a new instance of the <see cref="Startup" /> class.
  19. /// </summary>
  20. /// <param name="serverConfigurationManager">The server configuration manager.</param>
  21. public Startup(IServerConfigurationManager serverConfigurationManager)
  22. {
  23. _serverConfigurationManager = serverConfigurationManager;
  24. }
  25. /// <summary>
  26. /// Configures the service collection for the webhost.
  27. /// </summary>
  28. /// <param name="services">The service collection.</param>
  29. public void ConfigureServices(IServiceCollection services)
  30. {
  31. services.AddResponseCompression();
  32. services.AddHttpContextAccessor();
  33. services.AddJellyfinApi(_serverConfigurationManager.Configuration.BaseUrl.TrimStart('/'));
  34. services.AddJellyfinApiSwagger();
  35. // configure custom legacy authentication
  36. services.AddCustomAuthentication();
  37. services.AddJellyfinApiAuthorization();
  38. }
  39. /// <summary>
  40. /// Configures the app builder for the webhost.
  41. /// </summary>
  42. /// <param name="app">The application builder.</param>
  43. /// <param name="env">The webhost environment.</param>
  44. /// <param name="serverApplicationHost">The server application host.</param>
  45. public void Configure(
  46. IApplicationBuilder app,
  47. IWebHostEnvironment env,
  48. IServerApplicationHost serverApplicationHost)
  49. {
  50. if (env.IsDevelopment())
  51. {
  52. app.UseDeveloperExceptionPage();
  53. }
  54. app.UseMiddleware<ExceptionMiddleware>();
  55. app.UseWebSockets();
  56. app.UseResponseCompression();
  57. // TODO app.UseMiddleware<WebSocketMiddleware>();
  58. app.Use(serverApplicationHost.ExecuteWebsocketHandlerAsync);
  59. // TODO use when old API is removed: app.UseAuthentication();
  60. app.UseJellyfinApiSwagger(_serverConfigurationManager);
  61. app.UseRouting();
  62. app.UseAuthorization();
  63. app.UseEndpoints(endpoints =>
  64. {
  65. endpoints.MapControllers();
  66. });
  67. app.Use(serverApplicationHost.ExecuteHttpHandlerAsync);
  68. }
  69. }
  70. }