using System; using System.Collections.Generic; using System.IO; using Kyoo.Controllers; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.SpaServices.AngularCli; using Microsoft.AspNetCore.StaticFiles; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Hosting; namespace Kyoo.WebApp { /// /// A module to enable the web-app (the front-end of kyoo). /// public class WebAppModule : IPlugin { /// public string Slug => "webapp"; /// public string Name => "WebApp"; /// public string Description => "A module to enable the web-app (the front-end of kyoo)."; /// public Dictionary Configuration => new(); /// public void Configure(IServiceCollection services) { services.AddSpaStaticFiles(x => { x.RootPath = Path.Join(AppDomain.CurrentDomain.BaseDirectory, "wwwroot"); }); } /// public IEnumerable ConfigureSteps => new IStartupAction[] { SA.New((app, env) => { if (!env.IsDevelopment()) app.UseSpaStaticFiles(); }, SA.StaticFiles), SA.New((app, contentTypeProvider) => { app.UseStaticFiles(new StaticFileOptions { ContentTypeProvider = contentTypeProvider, FileProvider = new PhysicalFileProvider(Path.Join(AppDomain.CurrentDomain.BaseDirectory, "wwwroot")) }); }, SA.StaticFiles), SA.New(app => { app.Use((ctx, next) => { ctx.Response.Headers.Remove("X-Powered-By"); ctx.Response.Headers.Remove("Server"); ctx.Response.Headers.Add("Feature-Policy", "autoplay 'self'; fullscreen"); ctx.Response.Headers.Add("Content-Security-Policy", "default-src 'self' blob:; script-src 'self' blob: 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; frame-src 'self'"); ctx.Response.Headers.Add("X-Frame-Options", "SAMEORIGIN"); ctx.Response.Headers.Add("Referrer-Policy", "no-referrer"); ctx.Response.Headers.Add("Access-Control-Allow-Origin", "null"); ctx.Response.Headers.Add("X-Content-Type-Options", "nosniff"); return next(); }); }, SA.Endpoint - 499), SA.New((app, env) => { app.UseSpa(spa => { spa.Options.SourcePath = Path.Join(AppDomain.CurrentDomain.BaseDirectory, "Kyoo.WebApp"); if (env.IsDevelopment()) spa.UseAngularCliServer("start"); }); }, SA.Endpoint - 500) }; } }