-
-
Notifications
You must be signed in to change notification settings - Fork 122
/
Copy pathStartup.cs
74 lines (68 loc) · 3.3 KB
/
Startup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Net;
using System.Net.Http;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.ResponseCompression;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace FuGetGallery
{
public class Startup
{
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
NugetPackageSources.Configure (Configuration);
}
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
try {
new Database ().MigrateAsync ().Wait ();
services.AddScoped<Database, Database> ();
}
catch (Exception dbex) {
Console.WriteLine ($"Failed to open the database: {dbex}");
}
services.AddControllers();
services.AddRazorPages(options =>
{
options.Conventions.AddPageRoute("/packages/details", "packages/{id}");
options.Conventions.AddPageRoute("/packages/badges", "packages/{id}/badges");
options.Conventions.AddPageRoute("/packages/dependents", "packages/{id}/dependents");
options.Conventions.AddPageRoute("/packages/details", "packages/{id}/{version}");
options.Conventions.AddPageRoute("/packages/details", "packages/{id}/{version}/{dir}");
options.Conventions.AddPageRoute("/packages/details", "packages/{id}/{version}/{dir}/{targetFramework}");
options.Conventions.AddPageRoute("/packages/details", "packages/{id}/{version}/{dir}/{targetFramework}/{assemblyName}");
options.Conventions.AddPageRoute("/packages/details", "packages/{id}/{version}/{dir}/{targetFramework}/{assemblyName}/{namespace}");
options.Conventions.AddPageRoute("/packages/details", "packages/{id}/{version}/{dir}/{targetFramework}/{assemblyName}/{namespace}/{typeName}");
});
services.Configure<GzipCompressionProviderOptions>(options => options.Level = System.IO.Compression.CompressionLevel.Optimal);
services.AddResponseCompression();
services.AddHttpClient ("")
.ConfigurePrimaryHttpMessageHandler (() => new HttpClientHandler {
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseResponseCompression();
if (env.IsDevelopment()) {
app.UseDeveloperExceptionPage();
}
else {
app.UseExceptionHandler("/error");
}
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints (configure => {
configure.MapControllers ();
configure.MapRazorPages ();
});
}
}
}