|
1 | 1 | var builder = WebApplication.CreateBuilder(args);
|
2 |
| -builder.WebHost.UseContentRoot(Directory.GetCurrentDirectory()); |
3 | 2 |
|
4 |
| -builder.Services.AddApplicationInsightsTelemetry(builder.Configuration); |
5 |
| -builder.Services.AddApplicationInsightsKubernetesEnricher(); |
6 |
| -builder.Services.AddHealthChecks() |
7 |
| - .AddCheck("self", () => HealthCheckResult.Healthy()) |
8 |
| - .AddUrlGroup(new Uri(builder.Configuration["IdentityUrlHC"]), name: "identityapi-check", tags: new string[] { "identityapi" }); |
| 3 | +builder.AddServiceDefaults(); |
9 | 4 |
|
| 5 | +builder.Services.AddHealthChecks(builder.Configuration); |
10 | 6 | builder.Services.Configure<AppSettings>(builder.Configuration);
|
11 |
| -if (builder.Configuration.GetValue<string>("IsClusterEnv") == bool.TrueString) |
12 |
| -{ |
13 |
| - builder.Services.AddDataProtection(opts => |
14 |
| - { |
15 |
| - opts.ApplicationDiscriminator = "eshop.webspa"; |
16 |
| - }) |
17 |
| - .PersistKeysToStackExchangeRedis(ConnectionMultiplexer.Connect(builder.Configuration["DPConnectionString"]), "DataProtection-Keys"); |
18 |
| -} |
19 |
| - |
20 |
| - |
21 |
| -// Add Anti-forgery services and configure the header name that angular will use by default. |
22 |
| -builder.Services.AddAntiforgery(options => options.HeaderName = "X-XSRF-TOKEN"); |
23 |
| - |
24 |
| -// Add controllers support and add a global AutoValidateAntiforgeryTokenFilter that will make the application check for an Anti-forgery token on all "mutating" requests (POST, PUT, DELETE). |
25 |
| -// The AutoValidateAntiforgeryTokenFilter is an internal class registered when we register views, so we need to register controllers and views also. |
26 |
| -builder.Services.AddControllersWithViews(options => options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute())) |
27 |
| - .AddJsonOptions(options => |
28 |
| - { |
29 |
| - options.JsonSerializerOptions.PropertyNameCaseInsensitive = true; |
30 |
| - }); |
31 | 7 |
|
32 | 8 | // Setup where the compiled version of our spa application will be, when in production.
|
33 |
| -builder.Services.AddSpaStaticFiles(configuration => |
| 9 | +builder.Services.AddSpaStaticFiles(options => |
34 | 10 | {
|
35 |
| - configuration.RootPath = "wwwroot"; |
| 11 | + options.RootPath = "wwwroot"; |
36 | 12 | });
|
37 | 13 |
|
38 |
| -builder.Logging.AddConfiguration(builder.Configuration.GetSection("Logging")); |
39 |
| -builder.Logging.AddAzureWebAppDiagnostics(); |
40 |
| - |
41 | 14 | var app = builder.Build();
|
42 | 15 |
|
43 |
| -// Here we add Angular default Anti-forgery cookie name on first load. https://angular.io/guide/http#security-xsrf-protection |
44 |
| -// This cookie will be read by Angular app and its value will be sent back to the application as the header configured in .AddAntiforgery() |
45 |
| -var antiForgery = app.Services.GetRequiredService<IAntiforgery>(); |
46 |
| -app.Use(next => context => |
47 |
| -{ |
48 |
| - string path = context.Request.Path.Value; |
49 |
| - |
50 |
| - if (string.Equals(path, "/", StringComparison.OrdinalIgnoreCase) || |
51 |
| - string.Equals(path, "/index.html", StringComparison.OrdinalIgnoreCase)) |
52 |
| - { |
53 |
| - // The request token has to be sent as a JavaScript-readable cookie, |
54 |
| - // and Angular uses it by default. |
55 |
| - var tokens = antiForgery.GetAndStoreTokens(context); |
56 |
| - context.Response.Cookies.Append("XSRF-TOKEN", tokens.RequestToken, |
57 |
| - new CookieOptions() { HttpOnly = false }); |
58 |
| - } |
| 16 | +app.UseServiceDefaults(); |
59 | 17 |
|
60 |
| - return next(context); |
61 |
| -}); |
62 |
| - |
63 |
| -// Seed Data |
64 |
| -WebContextSeed.Seed(app, app.Environment, app.Services.GetRequiredService<ILogger<WebContextSeed>>()); |
65 |
| - |
66 |
| -var pathBase = app.Configuration["PATH_BASE"]; |
67 |
| - |
68 |
| -if (!string.IsNullOrEmpty(pathBase)) |
69 |
| -{ |
70 |
| - app.Services.GetRequiredService<ILogger<WebContextSeed>>().LogDebug("Using PATH_BASE '{PathBase}'", pathBase); |
71 |
| - app.UsePathBase(pathBase); |
72 |
| -} |
73 |
| - |
74 |
| -app.UseDefaultFiles(); |
75 |
| -app.UseStaticFiles(); |
| 18 | +app.UseFileServer(); |
76 | 19 |
|
77 | 20 | // This will make the application to respond with the index.html and the rest of the assets present on the configured folder (at AddSpaStaticFiles() (wwwroot))
|
78 | 21 | if (!app.Environment.IsDevelopment())
|
|
81 | 24 | }
|
82 | 25 |
|
83 | 26 | app.UseRouting();
|
84 |
| -app.MapDefaultControllerRoute(); |
85 |
| -app.MapControllers(); |
86 |
| -app.MapHealthChecks("/liveness", new HealthCheckOptions |
87 |
| -{ |
88 |
| - Predicate = r => r.Name.Contains("self") |
89 |
| -}); |
90 |
| -app.MapHealthChecks("/hc", new HealthCheckOptions() |
| 27 | + |
| 28 | +#pragma warning disable ASP0014 // Suggest using top level route registrations |
| 29 | +app.UseEndpoints(routes => |
91 | 30 | {
|
92 |
| - Predicate = _ => true, |
93 |
| - ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse |
| 31 | + // TODO: Change this route |
| 32 | + routes.MapGet("/home/configuration", (IOptions<AppSettings> options) => options.Value); |
94 | 33 | });
|
95 | 34 |
|
96 | 35 | // Handles all still unattended (by any other middleware) requests by returning the default page of the SPA (wwwroot/index.html).
|
|
109 | 48 | }
|
110 | 49 | });
|
111 | 50 |
|
| 51 | +// Seed Data |
| 52 | +WebContextSeed.Seed(app, app.Environment, app.Logger); |
| 53 | + |
112 | 54 | await app.RunAsync();
|
0 commit comments