winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

Startup.cs (3080B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 
      4 namespace LocalhostWebServer
      5 {
      6     using Microsoft.AspNetCore.Builder;
      7     using Microsoft.AspNetCore.Hosting;
      8     using Microsoft.AspNetCore.StaticFiles;
      9     using Microsoft.Extensions.Configuration;
     10     using Microsoft.Extensions.DependencyInjection;
     11     using Microsoft.Extensions.FileProviders;
     12     using Microsoft.Extensions.Hosting;
     13 
     14     public class Startup
     15     {
     16         public const string StaticFileRequestPath = "/TestKit";
     17 
     18         public static string StaticFileRoot { get; set; }
     19 
     20         public static string CertPath { get; set; }
     21 
     22         public static string CertPassword { get; set; }
     23 
     24         public static string OutCertFile { get; set; }
     25 
     26         public static int Port { get; set; }
     27 
     28         public static string LocalSourceJson { get; set; }
     29 
     30         public static string TestDataPath { get; set; }
     31 
     32         public static bool ExitBeforeRun { get; set; }
     33 
     34         public Startup(IConfiguration configuration)
     35         {
     36             Configuration = configuration;
     37         }
     38 
     39         public void ConfigureServices(IServiceCollection services)
     40         {
     41             services.AddControllersWithViews();
     42         }
     43 
     44         public IConfiguration Configuration { get; }
     45 
     46         public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
     47         {
     48             if (env.IsDevelopment())
     49             {
     50                 app.UseDeveloperExceptionPage();
     51             }
     52 
     53             app.UseHttpsRedirection();
     54 
     55             //Add .yaml and .msix mappings
     56             var provider = new FileExtensionContentTypeProvider();
     57             provider.Mappings[".yml"] = "application/x-yaml";
     58             provider.Mappings[".yaml"] = "application/x-yaml";
     59             provider.Mappings[".msix"] = "application/msix";
     60             provider.Mappings[".exe"] = "application/x-msdownload";
     61             provider.Mappings[".msi"] = "application/msi";
     62             provider.Mappings[".appx"] = "application/vns.ms-appx";
     63             provider.Mappings[".appxbundle"] = "application/vns.ms-appx";
     64             provider.Mappings[".mszyml"] = "application/x-ms-zip-yaml";
     65 
     66             //Enable static file serving
     67             app.UseStaticFiles(new StaticFileOptions
     68             {
     69                 FileProvider = new PhysicalFileProvider(StaticFileRoot),
     70                 RequestPath = StaticFileRequestPath,
     71                 ContentTypeProvider = provider,
     72                 ServeUnknownFileTypes = true,
     73                 DefaultContentType = "application/octet-stream"
     74             });
     75 
     76             app.UseDirectoryBrowser(new DirectoryBrowserOptions
     77             {
     78                 FileProvider = new PhysicalFileProvider(StaticFileRoot),
     79                 RequestPath = StaticFileRequestPath
     80             });
     81 
     82             app.UseRouting();
     83 
     84             app.UseAuthorization();
     85 
     86             app.UseEndpoints(endpoints =>
     87             {
     88                 endpoints.MapDefaultControllerRoute();
     89             });
     90         }
     91     }
     92 }