Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit 67d4c06

Browse files
authored
Fixed the spa project (#2126)
- Clean up the SPA project (removed dead code) - Fixed URLs in override file
1 parent 508fa59 commit 67d4c06

File tree

13 files changed

+55
-178
lines changed

13 files changed

+55
-178
lines changed

src/Web/WebSPA/AppSettings.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
public class AppSettings
44
{
55
public string IdentityUrl { get; set; }
6-
public string BasketUrl { get; set; }
76
public string MarketingUrl { get; set; }
87

98
public string PurchaseUrl { get; set; }
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
internal static class Extensions
2+
{
3+
public static IServiceCollection AddHealthChecks(this IServiceCollection services, IConfiguration configuration)
4+
{
5+
var hcBuilder = services.AddHealthChecks();
6+
7+
hcBuilder
8+
.AddUrlGroup(_ => new Uri(configuration["IdentityUrlHC"]), name: "identityapi-check", tags: new string[] { "identityapi" });
9+
10+
return services;
11+
}
12+
}

src/Web/WebSPA/GlobalUsings.cs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,6 @@
1-
global using eShopConContainers.WebSPA;
2-
global using Microsoft.AspNetCore;
3-
global using Microsoft.AspNetCore.Hosting;
4-
global using Microsoft.Extensions.Configuration;
5-
global using Microsoft.Extensions.Logging;
6-
global using System.IO;
1+
global using System.IO.Compression;
72
global using eShopOnContainers.WebSPA;
8-
global using HealthChecks.UI.Client;
9-
global using Microsoft.AspNetCore.Antiforgery;
10-
global using Microsoft.AspNetCore.Builder;
11-
global using Microsoft.AspNetCore.DataProtection;
12-
global using Microsoft.AspNetCore.Diagnostics.HealthChecks;
13-
global using Microsoft.AspNetCore.Http;
14-
global using Microsoft.AspNetCore.Mvc;
153
global using Microsoft.AspNetCore.SpaServices.AngularCli;
16-
global using Microsoft.Extensions.DependencyInjection;
17-
global using Microsoft.Extensions.Diagnostics.HealthChecks;
18-
global using Microsoft.Extensions.Hosting;
19-
global using StackExchange.Redis;
20-
global using System;
21-
global using WebSPA.Infrastructure;
224
global using Microsoft.Extensions.Options;
23-
global using System.IO.Compression;
24-
global using System.Linq;
5+
global using Services.Common;
6+
global using WebSPA.Infrastructure;

src/Web/WebSPA/Program.cs

Lines changed: 14 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,21 @@
11
var builder = WebApplication.CreateBuilder(args);
2-
builder.WebHost.UseContentRoot(Directory.GetCurrentDirectory());
32

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();
94

5+
builder.Services.AddHealthChecks(builder.Configuration);
106
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-
});
317

328
// Setup where the compiled version of our spa application will be, when in production.
33-
builder.Services.AddSpaStaticFiles(configuration =>
9+
builder.Services.AddSpaStaticFiles(options =>
3410
{
35-
configuration.RootPath = "wwwroot";
11+
options.RootPath = "wwwroot";
3612
});
3713

38-
builder.Logging.AddConfiguration(builder.Configuration.GetSection("Logging"));
39-
builder.Logging.AddAzureWebAppDiagnostics();
40-
4114
var app = builder.Build();
4215

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();
5917

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();
7619

7720
// 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))
7821
if (!app.Environment.IsDevelopment())
@@ -81,16 +24,12 @@
8124
}
8225

8326
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 =>
9130
{
92-
Predicate = _ => true,
93-
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
31+
// TODO: Change this route
32+
routes.MapGet("/home/configuration", (IOptions<AppSettings> options) => options.Value);
9433
});
9534

9635
// Handles all still unattended (by any other middleware) requests by returning the default page of the SPA (wwwroot/index.html).
@@ -109,4 +48,7 @@
10948
}
11049
});
11150

51+
// Seed Data
52+
WebContextSeed.Seed(app, app.Environment, app.Logger);
53+
11254
await app.RunAsync();
Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,5 @@
11
{
2-
"iisSettings": {
3-
"windowsAuthentication": false,
4-
"anonymousAuthentication": true,
5-
"iisExpress": {
6-
"applicationUrl": "http://localhost:58018/",
7-
"sslPort": 0
8-
}
9-
},
102
"profiles": {
11-
"IIS Express": {
12-
"commandName": "IISExpress",
13-
"environmentVariables": {
14-
"ASPNETCORE_ENVIRONMENT": "Development"
15-
}
16-
},
17-
"Docker": {
18-
"commandName": "Docker",
19-
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
20-
"publishAllPorts": true
21-
},
223
"WebSPA": {
234
"commandName": "Project",
245
"launchBrowser": true,
@@ -27,6 +8,11 @@
278
"ASPNETCORE_ENVIRONMENT": "Development"
289
},
2910
"applicationUrl": "http://localhost:5104"
11+
},
12+
"Docker": {
13+
"commandName": "Docker",
14+
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
15+
"publishAllPorts": true
3016
}
3117
}
3218
}

src/Web/WebSPA/Server/Controllers/HomeController.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/Web/WebSPA/Server/Infrastructure/WebContextSeed.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
public class WebContextSeed
66
{
7-
public static void Seed(IApplicationBuilder applicationBuilder, IWebHostEnvironment env, ILogger<WebContextSeed> logger)
7+
public static void Seed(IApplicationBuilder applicationBuilder, IWebHostEnvironment env, ILogger logger)
88
{
99
var settings = applicationBuilder
1010
.ApplicationServices.GetRequiredService<IOptions<AppSettings>>().Value;

src/Web/WebSPA/WebSPA.csproj

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
<PropertyGroup>
44
<TargetFramework>net7.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
56
<UserSecretsId>aspnetcorespa-c23d27a4-eb88-4b18-9b77-2a93f3b15119</UserSecretsId>
67
<TypeScriptCompileOnSaveEnabled>false</TypeScriptCompileOnSaveEnabled>
7-
<IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
88
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
99
<GeneratedItemPatterns>wwwroot/dist/**</GeneratedItemPatterns>
1010
<DefaultItemExcludes>$(DefaultItemExcludes);$(GeneratedItemPatterns)</DefaultItemExcludes>
@@ -22,26 +22,20 @@
2222
<Content Update="appsettings.json;">
2323
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
2424
</Content>
25-
<Content Update="web.config;">
26-
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
27-
</Content>
2825
<Content Update="wwwroot\**\*;">
2926
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
3027
</Content>
3128
</ItemGroup>
3229

3330
<ItemGroup>
34-
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" />
3531
<PackageReference Include="AspNetCore.HealthChecks.Uris" />
36-
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" />
37-
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" />
38-
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" />
3932
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" />
40-
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" />
4133
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" />
42-
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" />
4334
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" />
44-
<PackageReference Include="Newtonsoft.Json" />
35+
</ItemGroup>
36+
37+
<ItemGroup>
38+
<ProjectReference Include="..\..\Services\Services.Common\Services.Common.csproj" />
4539
</ItemGroup>
4640

4741
<Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">

src/Web/WebSPA/appsettings.json

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
{
2-
"IdentityUrl": "http://host.docker.internal:5105",
3-
"CallBackUrl": "http://host.docker.internal:5104/",
4-
"BasketUrl" : "http://host.docker.internal:5103",
5-
"PurchaseUrl": "http://host.docker.internal:5202",
6-
"PurchaseUrlHC": "http://host.docker.internal:5202/hc",
7-
"IdentityUrlHC": "http://host.docker.internal:5105/hc",
8-
"SignalrHubUrl": "http://host.docker.internal:5112",
9-
"UseCustomizationData": true,
10-
"IsClusterEnv": "False",
11-
"ActivateCampaignDetailFunction": false,
122
"Logging": {
13-
"Console": {
14-
"IncludeScopes": false
15-
},
163
"LogLevel": {
17-
"Default": "Debug",
18-
"System": "Information",
19-
"Microsoft": "Information"
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
206
}
217
},
8+
"IdentityUrl": "http://localhost:5223",
9+
"CallBackUrl": "http://localhost:5331/",
10+
"PurchaseUrl": "http://localhost:5229",
11+
"PurchaseUrlHC": "http://localhost:5229/hc",
12+
"IdentityUrlHC": "http://localhost:5223/hc",
13+
"SignalrHubUrl": "http://localhost:5229",
14+
"UseCustomizationData": true,
15+
"IsClusterEnv": false,
16+
"ActivateCampaignDetailFunction": false,
2217
"ApplicationInsights": {
2318
"InstrumentationKey": ""
2419
}

src/Web/WebSPA/web.config

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)