Fixed the spa project (#2126)
- Clean up the SPA project (removed dead code) - Fixed URLs in override file
This commit is contained in:
parent
508fa593d7
commit
67d4c06b6d
@ -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; }
|
||||
|
12
src/Web/WebSPA/Extensions/Extensions.cs
Normal file
12
src/Web/WebSPA/Extensions/Extensions.cs
Normal file
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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;
|
||||
app.UseServiceDefaults();
|
||||
|
||||
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 });
|
||||
}
|
||||
|
||||
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())
|
||||
@ -81,16 +24,12 @@ if (!app.Environment.IsDevelopment())
|
||||
}
|
||||
|
||||
app.UseRouting();
|
||||
app.MapDefaultControllerRoute();
|
||||
app.MapControllers();
|
||||
app.MapHealthChecks("/liveness", new HealthCheckOptions
|
||||
|
||||
#pragma warning disable ASP0014 // Suggest using top level route registrations
|
||||
app.UseEndpoints(routes =>
|
||||
{
|
||||
Predicate = r => r.Name.Contains("self")
|
||||
});
|
||||
app.MapHealthChecks("/hc", new HealthCheckOptions()
|
||||
{
|
||||
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).
|
||||
@ -109,4 +48,7 @@ app.UseSpa(spa =>
|
||||
}
|
||||
});
|
||||
|
||||
// Seed Data
|
||||
WebContextSeed.Seed(app, app.Environment, app.Logger);
|
||||
|
||||
await app.RunAsync();
|
||||
|
@ -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,
|
||||
@ -27,6 +8,11 @@
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "http://localhost:5104"
|
||||
},
|
||||
"Docker": {
|
||||
"commandName": "Docker",
|
||||
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
|
||||
"publishAllPorts": true
|
||||
}
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
// For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
|
||||
namespace eShopConContainers.WebSPA.Server.Controllers;
|
||||
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly IWebHostEnvironment _env;
|
||||
private readonly IOptionsSnapshot<AppSettings> _settings;
|
||||
|
||||
public HomeController(IWebHostEnvironment env, IOptionsSnapshot<AppSettings> settings)
|
||||
{
|
||||
_env = env;
|
||||
_settings = settings;
|
||||
}
|
||||
public IActionResult Configuration()
|
||||
{
|
||||
return Json(_settings.Value);
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ using Microsoft.Extensions.Logging;
|
||||
|
||||
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;
|
||||
|
@ -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>
|
||||
@ -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') ">
|
||||
|
@ -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": ""
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<!--
|
||||
Configure your application settings in appsettings.json. Learn more at https://go.microsoft.com/fwlink/?LinkId=786380
|
||||
-->
|
||||
<system.webServer>
|
||||
<handlers>
|
||||
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
|
||||
</handlers>
|
||||
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" hostingModel="InProcess">
|
||||
<environmentVariables />
|
||||
</aspNetCore>
|
||||
</system.webServer>
|
||||
</configuration>
|
@ -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
|
||||
- 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"
|
||||
|
||||
|
@ -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
|
||||
|
@ -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}
|
||||
|
Loading…
x
Reference in New Issue
Block a user