Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/Web/WebSPA/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
public class AppSettings
{
public string IdentityUrl { get; set; }
public string BasketUrl { get; set; }
public string MarketingUrl { get; set; }

public string PurchaseUrl { get; set; }
Expand Down
12 changes: 12 additions & 0 deletions src/Web/WebSPA/Extensions/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
internal static class Extensions
{
public static IServiceCollection AddHealthChecks(this IServiceCollection services, IConfiguration configuration)
{
var hcBuilder = services.AddHealthChecks();

hcBuilder
.AddUrlGroup(_ => new Uri(configuration["IdentityUrlHC"]), name: "identityapi-check", tags: new string[] { "identityapi" });

return services;
}
}
24 changes: 3 additions & 21 deletions src/Web/WebSPA/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
global using eShopConContainers.WebSPA;
global using Microsoft.AspNetCore;
global using Microsoft.AspNetCore.Hosting;
global using Microsoft.Extensions.Configuration;
global using Microsoft.Extensions.Logging;
global using System.IO;
global using System.IO.Compression;
global using eShopOnContainers.WebSPA;
global using HealthChecks.UI.Client;
global using Microsoft.AspNetCore.Antiforgery;
global using Microsoft.AspNetCore.Builder;
global using Microsoft.AspNetCore.DataProtection;
global using Microsoft.AspNetCore.Diagnostics.HealthChecks;
global using Microsoft.AspNetCore.Http;
global using Microsoft.AspNetCore.Mvc;
global using Microsoft.AspNetCore.SpaServices.AngularCli;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.Diagnostics.HealthChecks;
global using Microsoft.Extensions.Hosting;
global using StackExchange.Redis;
global using System;
global using WebSPA.Infrastructure;
global using Microsoft.Extensions.Options;
global using System.IO.Compression;
global using System.Linq;
global using Services.Common;
global using WebSPA.Infrastructure;
86 changes: 14 additions & 72 deletions src/Web/WebSPA/Program.cs
Original file line number Diff line number Diff line change
@@ -1,78 +1,21 @@
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseContentRoot(Directory.GetCurrentDirectory());

builder.Services.AddApplicationInsightsTelemetry(builder.Configuration);
builder.Services.AddApplicationInsightsKubernetesEnricher();
builder.Services.AddHealthChecks()
.AddCheck("self", () => HealthCheckResult.Healthy())
.AddUrlGroup(new Uri(builder.Configuration["IdentityUrlHC"]), name: "identityapi-check", tags: new string[] { "identityapi" });
builder.AddServiceDefaults();

builder.Services.AddHealthChecks(builder.Configuration);
builder.Services.Configure<AppSettings>(builder.Configuration);
if (builder.Configuration.GetValue<string>("IsClusterEnv") == bool.TrueString)
{
builder.Services.AddDataProtection(opts =>
{
opts.ApplicationDiscriminator = "eshop.webspa";
})
.PersistKeysToStackExchangeRedis(ConnectionMultiplexer.Connect(builder.Configuration["DPConnectionString"]), "DataProtection-Keys");
}


// Add Anti-forgery services and configure the header name that angular will use by default.
builder.Services.AddAntiforgery(options => options.HeaderName = "X-XSRF-TOKEN");

// 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).
// The AutoValidateAntiforgeryTokenFilter is an internal class registered when we register views, so we need to register controllers and views also.
builder.Services.AddControllersWithViews(options => options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute()))
.AddJsonOptions(options =>
{
options.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
});

// Setup where the compiled version of our spa application will be, when in production.
builder.Services.AddSpaStaticFiles(configuration =>
builder.Services.AddSpaStaticFiles(options =>
{
configuration.RootPath = "wwwroot";
options.RootPath = "wwwroot";
});

builder.Logging.AddConfiguration(builder.Configuration.GetSection("Logging"));
builder.Logging.AddAzureWebAppDiagnostics();

var app = builder.Build();

// Here we add Angular default Anti-forgery cookie name on first load. https://angular.io/guide/http#security-xsrf-protection
// This cookie will be read by Angular app and its value will be sent back to the application as the header configured in .AddAntiforgery()
var antiForgery = app.Services.GetRequiredService<IAntiforgery>();
app.Use(next => context =>
{
string path = context.Request.Path.Value;

if (string.Equals(path, "/", StringComparison.OrdinalIgnoreCase) ||
string.Equals(path, "/index.html", StringComparison.OrdinalIgnoreCase))
{
// The request token has to be sent as a JavaScript-readable cookie,
// and Angular uses it by default.
var tokens = antiForgery.GetAndStoreTokens(context);
context.Response.Cookies.Append("XSRF-TOKEN", tokens.RequestToken,
new CookieOptions() { HttpOnly = false });
}
app.UseServiceDefaults();

return next(context);
});

// Seed Data
WebContextSeed.Seed(app, app.Environment, app.Services.GetRequiredService<ILogger<WebContextSeed>>());

var pathBase = app.Configuration["PATH_BASE"];

if (!string.IsNullOrEmpty(pathBase))
{
app.Services.GetRequiredService<ILogger<WebContextSeed>>().LogDebug("Using PATH_BASE '{PathBase}'", pathBase);
app.UsePathBase(pathBase);
}

app.UseDefaultFiles();
app.UseStaticFiles();
app.UseFileServer();

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

app.UseRouting();
app.MapDefaultControllerRoute();
app.MapControllers();
app.MapHealthChecks("/liveness", new HealthCheckOptions
{
Predicate = r => r.Name.Contains("self")
});
app.MapHealthChecks("/hc", new HealthCheckOptions()

#pragma warning disable ASP0014 // Suggest using top level route registrations
app.UseEndpoints(routes =>
{
Predicate = _ => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
// TODO: Change this route
routes.MapGet("/home/configuration", (IOptions<AppSettings> options) => options.Value);
});

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

// Seed Data
WebContextSeed.Seed(app, app.Environment, app.Logger);

await app.RunAsync();
24 changes: 5 additions & 19 deletions src/Web/WebSPA/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:58018/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Docker": {
"commandName": "Docker",
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
"publishAllPorts": true
},
"WebSPA": {
"commandName": "Project",
"launchBrowser": true,
Expand All @@ -27,6 +8,11 @@
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:5104"
},
"Docker": {
"commandName": "Docker",
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
"publishAllPorts": true
}
}
}
18 changes: 0 additions & 18 deletions src/Web/WebSPA/Server/Controllers/HomeController.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Web/WebSPA/Server/Infrastructure/WebContextSeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class WebContextSeed
{
public static void Seed(IApplicationBuilder applicationBuilder, IWebHostEnvironment env, ILogger<WebContextSeed> logger)
public static void Seed(IApplicationBuilder applicationBuilder, IWebHostEnvironment env, ILogger logger)
{
var settings = applicationBuilder
.ApplicationServices.GetRequiredService<IOptions<AppSettings>>().Value;
Expand Down
16 changes: 5 additions & 11 deletions src/Web/WebSPA/WebSPA.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>aspnetcorespa-c23d27a4-eb88-4b18-9b77-2a93f3b15119</UserSecretsId>
<TypeScriptCompileOnSaveEnabled>false</TypeScriptCompileOnSaveEnabled>
<IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<GeneratedItemPatterns>wwwroot/dist/**</GeneratedItemPatterns>
<DefaultItemExcludes>$(DefaultItemExcludes);$(GeneratedItemPatterns)</DefaultItemExcludes>
Expand All @@ -22,26 +22,20 @@
<Content Update="appsettings.json;">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Update="web.config;">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Update="wwwroot\**\*;">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" />
<PackageReference Include="AspNetCore.HealthChecks.Uris" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" />
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" />
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" />
<PackageReference Include="Newtonsoft.Json" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Services\Services.Common\Services.Common.csproj" />
</ItemGroup>

<Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
Expand Down
27 changes: 11 additions & 16 deletions src/Web/WebSPA/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
{
"IdentityUrl": "http://host.docker.internal:5105",
"CallBackUrl": "http://host.docker.internal:5104/",
"BasketUrl" : "http://host.docker.internal:5103",
"PurchaseUrl": "http://host.docker.internal:5202",
"PurchaseUrlHC": "http://host.docker.internal:5202/hc",
"IdentityUrlHC": "http://host.docker.internal:5105/hc",
"SignalrHubUrl": "http://host.docker.internal:5112",
"UseCustomizationData": true,
"IsClusterEnv": "False",
"ActivateCampaignDetailFunction": false,
"Logging": {
"Console": {
"IncludeScopes": false
},
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"IdentityUrl": "http://localhost:5223",
"CallBackUrl": "http://localhost:5331/",
"PurchaseUrl": "http://localhost:5229",
"PurchaseUrlHC": "http://localhost:5229/hc",
"IdentityUrlHC": "http://localhost:5223/hc",
"SignalrHubUrl": "http://localhost:5229",
"UseCustomizationData": true,
"IsClusterEnv": false,
"ActivateCampaignDetailFunction": false,
"ApplicationInsights": {
"InstrumentationKey": ""
}
Expand Down
14 changes: 0 additions & 14 deletions src/Web/WebSPA/web.config

This file was deleted.

6 changes: 3 additions & 3 deletions src/docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,13 @@ services:
environment:
- ASPNETCORE_ENVIRONMENT=Production
- ASPNETCORE_URLS=http://0.0.0.0:80
- Identity__Url=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5105
- PurchaseUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5202
- IdentityUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5105
- PurchaseUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5121
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the real cors fix (going through the bff instead of envoy). I'll drop envoy from a future commit.

- IdentityUrlHC=http://identity-api/hc
- SignalrHubUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5121
- UseCustomizationData=True
- ApplicationInsights__InstrumentationKey=${INSTRUMENTATION_KEY}
- OrchestratorType=${ORCHESTRATOR_TYPE}
- SignalrHubUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5202
ports:
- "5104:80"

Expand Down
2 changes: 1 addition & 1 deletion src/docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ services:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=http://0.0.0.0:80
- Identity__Url=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5105
- IdentityUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5105
- PurchaseUrl=http://${ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP}:5202
- CatalogUrlHC=http://catalog-api/hc
- OrderingUrlHC=http://ordering-api/hc
Expand Down
1 change: 0 additions & 1 deletion src/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ services:
NODE_IMAGE: ${NODE_IMAGE:-node:16-bullseye}
depends_on:
- webshoppingagg
- webshoppingapigw

webmvc:
image: ${REGISTRY:-eshop}/webmvc:${PLATFORM:-linux}-${TAG:-latest}
Expand Down