From 4bb93e32cdcdc67d2ed79e6bad646a74cba7a50f Mon Sep 17 00:00:00 2001 From: hualin Date: Wed, 18 Dec 2024 13:02:39 +0800 Subject: [PATCH 01/15] support autorendermode --- .../CleanAspire.BlazorWebApp.Client.csproj | 15 +++ .../Layout/MainLayout.razor | 9 ++ .../Layout/MainLayout.razor.css | 20 +++ .../Pages/Home.razor | 7 + .../Program.cs | 9 ++ .../Routes.razor | 6 + .../_Imports.razor | 9 ++ .../CleanAspire.WebApp.csproj | 18 +++ .../Components/App.razor | 43 ++++++ .../Components/Pages/Error.razor | 36 +++++ .../Components/_Imports.razor | 11 ++ .../CleanAspire.BlazorWebApp/Program.cs | 125 ++++++++++++++++++ .../Properties/launchSettings.json | 25 ++++ .../appsettings.Development.json | 13 ++ .../CleanAspire.BlazorWebApp/appsettings.json | 14 ++ .../CleanAspire.BlazorWebApp/wwwroot/app.css | 38 ++++++ CleanAspire.sln | 7 + src/CleanAspire.Api/appsettings.json | 2 +- .../CleanAspire.AppHost.csproj | 4 +- src/CleanAspire.AppHost/Program.cs | 2 +- .../CleanAspire.ClientApp.csproj | 2 + .../DependencyInjection.cs | 33 +++++ .../Layout/MainLayout.razor | 6 +- src/CleanAspire.ClientApp/Program.cs | 4 +- src/CleanAspire.ClientApp/Routes.razor | 12 ++ .../CookieAuthenticationStateProvider.cs | 4 +- 26 files changed, 464 insertions(+), 10 deletions(-) create mode 100644 CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/CleanAspire.BlazorWebApp.Client.csproj create mode 100644 CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Layout/MainLayout.razor create mode 100644 CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Layout/MainLayout.razor.css create mode 100644 CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Pages/Home.razor create mode 100644 CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Program.cs create mode 100644 CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Routes.razor create mode 100644 CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/_Imports.razor create mode 100644 CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/CleanAspire.WebApp.csproj create mode 100644 CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Components/App.razor create mode 100644 CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Components/Pages/Error.razor create mode 100644 CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Components/_Imports.razor create mode 100644 CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Program.cs create mode 100644 CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Properties/launchSettings.json create mode 100644 CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/appsettings.Development.json create mode 100644 CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/appsettings.json create mode 100644 CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/wwwroot/app.css create mode 100644 src/CleanAspire.ClientApp/Routes.razor diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/CleanAspire.BlazorWebApp.Client.csproj b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/CleanAspire.BlazorWebApp.Client.csproj new file mode 100644 index 0000000..91cf2d2 --- /dev/null +++ b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/CleanAspire.BlazorWebApp.Client.csproj @@ -0,0 +1,15 @@ + + + + net9.0 + enable + enable + true + Default + + + + + + + diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Layout/MainLayout.razor b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Layout/MainLayout.razor new file mode 100644 index 0000000..96fbbe6 --- /dev/null +++ b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Layout/MainLayout.razor @@ -0,0 +1,9 @@ +@inherits LayoutComponentBase + +@Body + +
+ An unhandled error has occurred. + Reload + 🗙 +
diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Layout/MainLayout.razor.css b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Layout/MainLayout.razor.css new file mode 100644 index 0000000..60cec92 --- /dev/null +++ b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Layout/MainLayout.razor.css @@ -0,0 +1,20 @@ +#blazor-error-ui { + color-scheme: light only; + background: lightyellow; + bottom: 0; + box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2); + box-sizing: border-box; + display: none; + left: 0; + padding: 0.6rem 1.25rem 0.7rem 1.25rem; + position: fixed; + width: 100%; + z-index: 1000; +} + + #blazor-error-ui .dismiss { + cursor: pointer; + position: absolute; + right: 0.75rem; + top: 0.5rem; + } diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Pages/Home.razor b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Pages/Home.razor new file mode 100644 index 0000000..9001e0b --- /dev/null +++ b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Pages/Home.razor @@ -0,0 +1,7 @@ +@page "/" + +Home + +

Hello, world!

+ +Welcome to your new app. diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Program.cs b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Program.cs new file mode 100644 index 0000000..7f55b12 --- /dev/null +++ b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Program.cs @@ -0,0 +1,9 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Microsoft.AspNetCore.Components.WebAssembly.Hosting; + +var builder = WebAssemblyHostBuilder.CreateDefault(args); + +await builder.Build().RunAsync(); diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Routes.razor b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Routes.razor new file mode 100644 index 0000000..f756e19 --- /dev/null +++ b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Routes.razor @@ -0,0 +1,6 @@ + + + + + + diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/_Imports.razor b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/_Imports.razor new file mode 100644 index 0000000..fbb08a6 --- /dev/null +++ b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/_Imports.razor @@ -0,0 +1,9 @@ +@using System.Net.Http +@using System.Net.Http.Json +@using Microsoft.AspNetCore.Components.Forms +@using Microsoft.AspNetCore.Components.Routing +@using Microsoft.AspNetCore.Components.Web +@using static Microsoft.AspNetCore.Components.Web.RenderMode +@using Microsoft.AspNetCore.Components.Web.Virtualization +@using Microsoft.JSInterop +@using CleanAspire.BlazorWebApp.Client diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/CleanAspire.WebApp.csproj b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/CleanAspire.WebApp.csproj new file mode 100644 index 0000000..fae3421 --- /dev/null +++ b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/CleanAspire.WebApp.csproj @@ -0,0 +1,18 @@ + + + + net9.0 + enable + enable + + + + + + + + + + + + diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Components/App.razor b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Components/App.razor new file mode 100644 index 0000000..4155de4 --- /dev/null +++ b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Components/App.razor @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Components/Pages/Error.razor b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Components/Pages/Error.razor new file mode 100644 index 0000000..576cc2d --- /dev/null +++ b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Components/Pages/Error.razor @@ -0,0 +1,36 @@ +@page "/Error" +@using System.Diagnostics + +Error + +

Error.

+

An error occurred while processing your request.

+ +@if (ShowRequestId) +{ +

+ Request ID: @RequestId +

+} + +

Development Mode

+

+ Swapping to Development environment will display more detailed information about the error that occurred. +

+

+ The Development environment shouldn't be enabled for deployed applications. + It can result in displaying sensitive information from exceptions to end users. + For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development + and restarting the app. +

+ +@code{ + [CascadingParameter] + private HttpContext? HttpContext { get; set; } + + private string? RequestId { get; set; } + private bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + + protected override void OnInitialized() => + RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier; +} diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Components/_Imports.razor b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Components/_Imports.razor new file mode 100644 index 0000000..b5146a8 --- /dev/null +++ b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Components/_Imports.razor @@ -0,0 +1,11 @@ +@using System.Net.Http +@using System.Net.Http.Json +@using Microsoft.AspNetCore.Components.Forms +@using Microsoft.AspNetCore.Components.Routing +@using Microsoft.AspNetCore.Components.Web +@using static Microsoft.AspNetCore.Components.Web.RenderMode +@using Microsoft.AspNetCore.Components.Web.Virtualization +@using Microsoft.JSInterop +@using CleanAspire.WebApp +@using CleanAspire.ClientApp +@using CleanAspire.WebApp.Components diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Program.cs b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Program.cs new file mode 100644 index 0000000..6e4d083 --- /dev/null +++ b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Program.cs @@ -0,0 +1,125 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using CleanAspire.Api.Client; +using CleanAspire.ClientApp.Configurations; +using CleanAspire.ClientApp.Services; +using CleanAspire.ClientApp.Services.Identity; +using CleanAspire.ClientApp.Services.JsInterop; +using CleanAspire.ClientApp.Services.Proxies; +using Microsoft.AspNetCore.Components.Authorization; +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Abstractions.Authentication; +using Microsoft.Kiota.Http.HttpClientLibrary; +using Microsoft.Kiota.Serialization.Form; +using Microsoft.Kiota.Serialization.Json; +using Microsoft.Kiota.Serialization.Multipart; +using Microsoft.Kiota.Serialization.Text; +using CleanAspire.ClientApp; + + +var builder = WebApplication.CreateBuilder(args); +builder.AddServiceDefaults(); +// Add services to the container. +builder.Services.AddRazorComponents() + .AddInteractiveServerComponents() + .AddInteractiveWebAssemblyComponents(); + + + +// register the cookie handler +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); + +var clientAppSettings = builder.Configuration.GetSection(ClientAppSettings.KEY).Get(); +builder.Services.AddSingleton(clientAppSettings!); + +builder.Services.TryAddScopedMudBlazor(builder.Configuration); + +var httpClientBuilder = builder.Services.AddHttpClient("apiservice", (sp, options) => +{ + var settings = sp.GetRequiredService(); + options.BaseAddress = new Uri(settings.ServiceBaseUrl); + +}).AddHttpMessageHandler(); + +builder.Services.AddScoped(sp => +{ + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + var settings = sp.GetRequiredService(); + var httpClientFactory = sp.GetRequiredService(); + var httpClient = httpClientFactory.CreateClient("apiservice"); + var authProvider = new AnonymousAuthenticationProvider(); + var requestAdapter = new HttpClientRequestAdapter(authProvider, httpClient: httpClient); + var apiClient = new ApiClient(requestAdapter); + if (!string.IsNullOrEmpty(settings.ServiceBaseUrl)) + { + requestAdapter.BaseUrl = settings.ServiceBaseUrl; + } + return apiClient; + +}); +builder.Services.AddHttpClient("Webpushr", client => +{ + client.BaseAddress = new Uri("https://api.webpushr.com"); +}).AddHttpMessageHandler(); +builder.Services.AddScoped(); + +builder.Services.AddScoped(); +builder.Services.AddAuthorizationCore(); +builder.Services.AddCascadingAuthenticationState(); +builder.Services.AddOidcAuthentication(options => +{ + // Configure your authentication provider options here. + // For more information, see https://aka.ms/blazor-standalone-auth + builder.Configuration.Bind("Local", options.ProviderOptions); +}); +// register the custom state provider +builder.Services.AddScoped(); + +// register the account management interface +builder.Services.AddScoped( + sp => (ISignInManagement)sp.GetRequiredService()); + + +builder.Services.AddLocalization(options => options.ResourcesPath = "Resources"); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseWebAssemblyDebugging(); +} +else +{ + app.UseExceptionHandler("/Error", createScopeForErrors: true); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); +} + +app.UseHttpsRedirection(); + + +app.UseAntiforgery(); + +app.MapStaticAssets(); +app.MapRazorComponents() + .AddInteractiveServerRenderMode() + .AddInteractiveWebAssemblyRenderMode() + .AddAdditionalAssemblies(typeof(CleanAspire.ClientApp._Imports).Assembly); + +app.Run(); diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Properties/launchSettings.json b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Properties/launchSettings.json new file mode 100644 index 0000000..393d6ac --- /dev/null +++ b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Properties/launchSettings.json @@ -0,0 +1,25 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", + "applicationUrl": "http://localhost:5252", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", + "applicationUrl": "https://localhost:7114;http://localhost:5252", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } + } diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/appsettings.Development.json b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/appsettings.Development.json new file mode 100644 index 0000000..fa07868 --- /dev/null +++ b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/appsettings.Development.json @@ -0,0 +1,13 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "ClientAppSettings": { + "AppName": "Progressive Web Application", + "Version": "v0.0.50", + "ServiceBaseUrl": "https://localhost:7341" + } +} diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/appsettings.json b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/appsettings.json new file mode 100644 index 0000000..e5058b9 --- /dev/null +++ b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/appsettings.json @@ -0,0 +1,14 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*", + "ClientAppSettings": { + "AppName": "Progressive Web Application", + "Version": "v0.0.50", + "ServiceBaseUrl": "https://apiservice.blazorserver.com" + } +} diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/wwwroot/app.css b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/wwwroot/app.css new file mode 100644 index 0000000..5388357 --- /dev/null +++ b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/wwwroot/app.css @@ -0,0 +1,38 @@ +h1:focus { + outline: none; +} + +.valid.modified:not([type=checkbox]) { + outline: 1px solid #26b050; +} + +.invalid { + outline: 1px solid #e50000; +} + +.validation-message { + color: #e50000; +} + +.blazor-error-boundary { + background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121; + padding: 1rem 1rem 1rem 3.7rem; + color: white; +} + + .blazor-error-boundary::after { + content: "An error has occurred." + } + +.darker-border-checkbox.form-check-input { + border-color: #929292; +} + +.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder { + color: var(--bs-secondary-color); + text-align: end; +} + +.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder { + text-align: start; +} \ No newline at end of file diff --git a/CleanAspire.sln b/CleanAspire.sln index 9ae4386..629d0dd 100644 --- a/CleanAspire.sln +++ b/CleanAspire.sln @@ -35,6 +35,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{0AB3BF05 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CleanAspire.Tests", "tests\CleanAspire.Tests\CleanAspire.Tests.csproj", "{184DD222-E87D-65E3-4E4F-ADC8680E2D81}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CleanAspire.WebApp", "CleanAspire.BlazorWebApp\CleanAspire.BlazorWebApp\CleanAspire.WebApp.csproj", "{E29307F2-485B-47B4-9CA7-A7EA6949134B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -85,6 +87,10 @@ Global {184DD222-E87D-65E3-4E4F-ADC8680E2D81}.Debug|Any CPU.Build.0 = Debug|Any CPU {184DD222-E87D-65E3-4E4F-ADC8680E2D81}.Release|Any CPU.ActiveCfg = Release|Any CPU {184DD222-E87D-65E3-4E4F-ADC8680E2D81}.Release|Any CPU.Build.0 = Release|Any CPU + {E29307F2-485B-47B4-9CA7-A7EA6949134B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E29307F2-485B-47B4-9CA7-A7EA6949134B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E29307F2-485B-47B4-9CA7-A7EA6949134B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E29307F2-485B-47B4-9CA7-A7EA6949134B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -102,6 +108,7 @@ Global {7D6E47CC-90F1-4C19-AF96-1DE7EED7928C} = {C983071D-42D7-4326-A379-CE622E29D307} {67226F2C-5D75-4B76-B5F8-E42A4BC1BBB1} = {C983071D-42D7-4326-A379-CE622E29D307} {184DD222-E87D-65E3-4E4F-ADC8680E2D81} = {0AB3BF05-4346-4AA6-1389-037BE0695223} + {E29307F2-485B-47B4-9CA7-A7EA6949134B} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C379C278-2AFA-4DD5-96F5-34D17AAE1188} diff --git a/src/CleanAspire.Api/appsettings.json b/src/CleanAspire.Api/appsettings.json index 1e2bc1b..47f17a8 100644 --- a/src/CleanAspire.Api/appsettings.json +++ b/src/CleanAspire.Api/appsettings.json @@ -6,7 +6,7 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedCorsOrigins": "https://localhost:7341,https://localhost:7123", + "AllowedCorsOrigins": "https://localhost:7341,https://localhost:7123,https://localhost:7114", "ClientBaseUrl": "https://localhost:7123", "DatabaseSettings": { "DBProvider": "sqlite", diff --git a/src/CleanAspire.AppHost/CleanAspire.AppHost.csproj b/src/CleanAspire.AppHost/CleanAspire.AppHost.csproj index 9438a76..f366b5e 100644 --- a/src/CleanAspire.AppHost/CleanAspire.AppHost.csproj +++ b/src/CleanAspire.AppHost/CleanAspire.AppHost.csproj @@ -1,4 +1,4 @@ - + @@ -15,8 +15,8 @@ + - diff --git a/src/CleanAspire.AppHost/Program.cs b/src/CleanAspire.AppHost/Program.cs index f508ce0..c29c626 100644 --- a/src/CleanAspire.AppHost/Program.cs +++ b/src/CleanAspire.AppHost/Program.cs @@ -2,7 +2,7 @@ var apiService = builder.AddProject("apiservice"); -builder.AddProject("webfrontend") +builder.AddProject("blazorweb") .WithExternalHttpEndpoints() .WithReference(apiService) .WaitFor(apiService); diff --git a/src/CleanAspire.ClientApp/CleanAspire.ClientApp.csproj b/src/CleanAspire.ClientApp/CleanAspire.ClientApp.csproj index 62198d0..c79c91b 100644 --- a/src/CleanAspire.ClientApp/CleanAspire.ClientApp.csproj +++ b/src/CleanAspire.ClientApp/CleanAspire.ClientApp.csproj @@ -4,6 +4,8 @@ net9.0 enable enable + true + Default service-worker-assets.js CleanAspire.ClientApp CleanAspire.ClientApp diff --git a/src/CleanAspire.ClientApp/DependencyInjection.cs b/src/CleanAspire.ClientApp/DependencyInjection.cs index 2b60731..c01e3fe 100644 --- a/src/CleanAspire.ClientApp/DependencyInjection.cs +++ b/src/CleanAspire.ClientApp/DependencyInjection.cs @@ -10,6 +10,39 @@ namespace CleanAspire.ClientApp; public static class DependencyInjection { + public static void TryAddScopedMudBlazor(this IServiceCollection services, IConfiguration config) + { + #region register MudBlazor.Services + services.AddMudServices(config => + { + MudGlobal.InputDefaults.ShrinkLabel = true; + config.SnackbarConfiguration.PositionClass = Defaults.Classes.Position.BottomCenter; + config.SnackbarConfiguration.NewestOnTop = false; + config.SnackbarConfiguration.ShowCloseIcon = true; + config.SnackbarConfiguration.VisibleStateDuration = 3000; + config.SnackbarConfiguration.HideTransitionDuration = 500; + config.SnackbarConfiguration.ShowTransitionDuration = 500; + config.SnackbarConfiguration.SnackbarVariant = Variant.Filled; + + // we're currently planning on deprecating `PreventDuplicates`, at least to the end dev. however, + // we may end up wanting to instead set it as internal because the docs project relies on it + // to ensure that the Snackbar always allows duplicates. disabling the warning for now because + // the project is set to treat warnings as errors. +#pragma warning disable 0618 + config.SnackbarConfiguration.PreventDuplicates = false; +#pragma warning restore 0618 + }); + services.AddMudPopoverService(); + services.AddMudBlazorSnackbar(); + services.AddMudBlazorDialog(); + services.AddMudLocalization(); + services.AddBlazoredLocalStorage(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + #endregion + } public static void TryAddMudBlazor(this IServiceCollection services, IConfiguration config) { #region register MudBlazor.Services diff --git a/src/CleanAspire.ClientApp/Layout/MainLayout.razor b/src/CleanAspire.ClientApp/Layout/MainLayout.razor index 0f13f01..d7f5d2e 100644 --- a/src/CleanAspire.ClientApp/Layout/MainLayout.razor +++ b/src/CleanAspire.ClientApp/Layout/MainLayout.razor @@ -21,8 +21,8 @@ { LayoutService.MajorUpdateOccurred += LayoutServiceOnMajorUpdateOccured; } - OnlineStatusInterop.Initialize(); - await OfflineModeState.InitializeAsync(); + + } protected override async Task OnAfterRenderAsync(bool firstRender) @@ -31,6 +31,8 @@ if (firstRender) { + OnlineStatusInterop.Initialize(); + await OfflineModeState.InitializeAsync(); await ApplyUserPreferences(); if (_mudThemeProvider != null) { diff --git a/src/CleanAspire.ClientApp/Program.cs b/src/CleanAspire.ClientApp/Program.cs index 1b442f3..43ae928 100644 --- a/src/CleanAspire.ClientApp/Program.cs +++ b/src/CleanAspire.ClientApp/Program.cs @@ -18,8 +18,8 @@ var builder = WebAssemblyHostBuilder.CreateDefault(args); -builder.RootComponents.Add("#app"); -builder.RootComponents.Add("head::after"); +//builder.RootComponents.Add("#app"); +//builder.RootComponents.Add("head::after"); // register the cookie handler builder.Services.AddTransient(); diff --git a/src/CleanAspire.ClientApp/Routes.razor b/src/CleanAspire.ClientApp/Routes.razor new file mode 100644 index 0000000..6fd3ed1 --- /dev/null +++ b/src/CleanAspire.ClientApp/Routes.razor @@ -0,0 +1,12 @@ + + + + + + + Not found + +

Sorry, there's nothing at this address.

+
+
+
diff --git a/src/CleanAspire.ClientApp/Services/Identity/CookieAuthenticationStateProvider.cs b/src/CleanAspire.ClientApp/Services/Identity/CookieAuthenticationStateProvider.cs index 475d8eb..be41576 100644 --- a/src/CleanAspire.ClientApp/Services/Identity/CookieAuthenticationStateProvider.cs +++ b/src/CleanAspire.ClientApp/Services/Identity/CookieAuthenticationStateProvider.cs @@ -25,13 +25,13 @@ public override async Task GetAuthenticationStateAsync() var indexedDb = serviceProvider.GetRequiredService(); var onlineStatusInterop = serviceProvider.GetRequiredService(); var offlineState = serviceProvider.GetRequiredService(); - bool enableOffline = offlineState.Enabled; authenticated = false; // default to not authenticated var user = unauthenticated; ProfileResponse? profileResponse = null; try { + bool enableOffline = offlineState.Enabled; var isOnline = await onlineStatusInterop.GetOnlineStatusAsync(); if (isOnline) { @@ -78,9 +78,9 @@ public async Task LoginAsync(LoginRequest request, bool remember = true, Cancell var indexedDb = serviceProvider.GetRequiredService(); var onlineStatusInterop = serviceProvider.GetRequiredService(); var offlineState = serviceProvider.GetRequiredService(); - bool offlineModel = offlineState.Enabled; try { + bool offlineModel = offlineState.Enabled; var isOnline = await onlineStatusInterop.GetOnlineStatusAsync(); if (isOnline) { From 5b8a41f209a497aaa531296d403ebaa1de15bd91 Mon Sep 17 00:00:00 2001 From: hualin Date: Wed, 18 Dec 2024 13:25:39 +0800 Subject: [PATCH 02/15] create dockerfile --- .dockerignore | 30 +++++++++ .../CleanAspire.BlazorWebApp.Client.csproj | 15 ----- .../Layout/MainLayout.razor | 9 --- .../Layout/MainLayout.razor.css | 20 ------ .../Pages/Home.razor | 7 --- .../Program.cs | 9 --- .../Routes.razor | 6 -- .../_Imports.razor | 9 --- .../Properties/launchSettings.json | 25 -------- CleanAspire.sln | 2 +- src/CleanAspire.ClientApp/Dockerfile | 42 ------------- src/CleanAspire.ClientApp/nginx.conf | 31 ---------- .../CleanAspire.WebApp.csproj | 6 +- .../CleanAspire.WebApp}/Components/App.razor | 0 .../Components/Pages/Error.razor | 0 .../Components/_Imports.razor | 0 src/CleanAspire.WebApp/Dockerfile | 61 +++++++++++++++++++ .../CleanAspire.WebApp}/Program.cs | 0 .../Properties/launchSettings.json | 36 +++++++++++ .../appsettings.Development.json | 0 .../CleanAspire.WebApp}/appsettings.json | 0 .../CleanAspire.WebApp}/wwwroot/app.css | 0 22 files changed, 133 insertions(+), 175 deletions(-) create mode 100644 .dockerignore delete mode 100644 CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/CleanAspire.BlazorWebApp.Client.csproj delete mode 100644 CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Layout/MainLayout.razor delete mode 100644 CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Layout/MainLayout.razor.css delete mode 100644 CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Pages/Home.razor delete mode 100644 CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Program.cs delete mode 100644 CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Routes.razor delete mode 100644 CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/_Imports.razor delete mode 100644 CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Properties/launchSettings.json delete mode 100644 src/CleanAspire.ClientApp/Dockerfile delete mode 100644 src/CleanAspire.ClientApp/nginx.conf rename {CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp => src/CleanAspire.WebApp}/CleanAspire.WebApp.csproj (62%) rename {CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp => src/CleanAspire.WebApp}/Components/App.razor (100%) rename {CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp => src/CleanAspire.WebApp}/Components/Pages/Error.razor (100%) rename {CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp => src/CleanAspire.WebApp}/Components/_Imports.razor (100%) create mode 100644 src/CleanAspire.WebApp/Dockerfile rename {CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp => src/CleanAspire.WebApp}/Program.cs (100%) create mode 100644 src/CleanAspire.WebApp/Properties/launchSettings.json rename {CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp => src/CleanAspire.WebApp}/appsettings.Development.json (100%) rename {CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp => src/CleanAspire.WebApp}/appsettings.json (100%) rename {CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp => src/CleanAspire.WebApp}/wwwroot/app.css (100%) diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..fe1152b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,30 @@ +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md +!**/.gitignore +!.git/HEAD +!.git/config +!.git/packed-refs +!.git/refs/heads/** \ No newline at end of file diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/CleanAspire.BlazorWebApp.Client.csproj b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/CleanAspire.BlazorWebApp.Client.csproj deleted file mode 100644 index 91cf2d2..0000000 --- a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/CleanAspire.BlazorWebApp.Client.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - - net9.0 - enable - enable - true - Default - - - - - - - diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Layout/MainLayout.razor b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Layout/MainLayout.razor deleted file mode 100644 index 96fbbe6..0000000 --- a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Layout/MainLayout.razor +++ /dev/null @@ -1,9 +0,0 @@ -@inherits LayoutComponentBase - -@Body - -
- An unhandled error has occurred. - Reload - 🗙 -
diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Layout/MainLayout.razor.css b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Layout/MainLayout.razor.css deleted file mode 100644 index 60cec92..0000000 --- a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Layout/MainLayout.razor.css +++ /dev/null @@ -1,20 +0,0 @@ -#blazor-error-ui { - color-scheme: light only; - background: lightyellow; - bottom: 0; - box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2); - box-sizing: border-box; - display: none; - left: 0; - padding: 0.6rem 1.25rem 0.7rem 1.25rem; - position: fixed; - width: 100%; - z-index: 1000; -} - - #blazor-error-ui .dismiss { - cursor: pointer; - position: absolute; - right: 0.75rem; - top: 0.5rem; - } diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Pages/Home.razor b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Pages/Home.razor deleted file mode 100644 index 9001e0b..0000000 --- a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Pages/Home.razor +++ /dev/null @@ -1,7 +0,0 @@ -@page "/" - -Home - -

Hello, world!

- -Welcome to your new app. diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Program.cs b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Program.cs deleted file mode 100644 index 7f55b12..0000000 --- a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Program.cs +++ /dev/null @@ -1,9 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using Microsoft.AspNetCore.Components.WebAssembly.Hosting; - -var builder = WebAssemblyHostBuilder.CreateDefault(args); - -await builder.Build().RunAsync(); diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Routes.razor b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Routes.razor deleted file mode 100644 index f756e19..0000000 --- a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/Routes.razor +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/_Imports.razor b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/_Imports.razor deleted file mode 100644 index fbb08a6..0000000 --- a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp.Client/_Imports.razor +++ /dev/null @@ -1,9 +0,0 @@ -@using System.Net.Http -@using System.Net.Http.Json -@using Microsoft.AspNetCore.Components.Forms -@using Microsoft.AspNetCore.Components.Routing -@using Microsoft.AspNetCore.Components.Web -@using static Microsoft.AspNetCore.Components.Web.RenderMode -@using Microsoft.AspNetCore.Components.Web.Virtualization -@using Microsoft.JSInterop -@using CleanAspire.BlazorWebApp.Client diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Properties/launchSettings.json b/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Properties/launchSettings.json deleted file mode 100644 index 393d6ac..0000000 --- a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Properties/launchSettings.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/launchsettings.json", - "profiles": { - "http": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", - "applicationUrl": "http://localhost:5252", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "https": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", - "applicationUrl": "https://localhost:7114;http://localhost:5252", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - } - } - } diff --git a/CleanAspire.sln b/CleanAspire.sln index 629d0dd..094f84b 100644 --- a/CleanAspire.sln +++ b/CleanAspire.sln @@ -35,7 +35,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{0AB3BF05 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CleanAspire.Tests", "tests\CleanAspire.Tests\CleanAspire.Tests.csproj", "{184DD222-E87D-65E3-4E4F-ADC8680E2D81}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CleanAspire.WebApp", "CleanAspire.BlazorWebApp\CleanAspire.BlazorWebApp\CleanAspire.WebApp.csproj", "{E29307F2-485B-47B4-9CA7-A7EA6949134B}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CleanAspire.WebApp", "src\CleanAspire.WebApp\CleanAspire.WebApp.csproj", "{E29307F2-485B-47B4-9CA7-A7EA6949134B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/CleanAspire.ClientApp/Dockerfile b/src/CleanAspire.ClientApp/Dockerfile deleted file mode 100644 index f54f7bd..0000000 --- a/src/CleanAspire.ClientApp/Dockerfile +++ /dev/null @@ -1,42 +0,0 @@ -# Stage 1: Build the Blazor Client Application -FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build -WORKDIR /src - -# Install Python for AOT compilation -RUN apt-get update && apt-get install -y python3 python3-pip && ln -s /usr/bin/python3 /usr/bin/python - -# Copy the project files and restore dependencies -COPY ["src/CleanAspire.ClientApp/CleanAspire.ClientApp.csproj", "src/CleanAspire.ClientApp/"] -RUN dotnet restore "src/CleanAspire.ClientApp/CleanAspire.ClientApp.csproj" - -# Install wasm-tools for AOT -RUN dotnet workload install wasm-tools --skip-manifest-update -RUN dotnet workload update - -# Copy the entire source code and build the application in Release mode -COPY . . -RUN dotnet publish -c Release -o /app/publish - -# Stage 2: Serve the Blazor Client Application using Nginx -FROM nginx:alpine AS final -WORKDIR /usr/share/nginx/html - -# Install OpenSSL to create a self-signed certificate -RUN apk add --no-cache openssl && \ - openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt -subj "/CN=localhost" - -# Clean the default nginx content -RUN rm -rf ./* - -# Copy the build output from the previous stage -COPY --from=build /app/publish/wwwroot . - -# Copy the generated self-signed certificate and configure Nginx for HTTPS -COPY src/CleanAspire.ClientApp/nginx.conf /etc/nginx/nginx.conf - -# Expose port 80 for HTTP traffic and 443 for HTTPS traffic -EXPOSE 80 -EXPOSE 443 - -# Start Nginx -CMD ["nginx", "-g", "daemon off;"] diff --git a/src/CleanAspire.ClientApp/nginx.conf b/src/CleanAspire.ClientApp/nginx.conf deleted file mode 100644 index 213d968..0000000 --- a/src/CleanAspire.ClientApp/nginx.conf +++ /dev/null @@ -1,31 +0,0 @@ -worker_processes auto; - -events { - worker_connections 1024; -} - -http { - include /etc/nginx/mime.types; - default_type application/octet-stream; - - # Define a server block here - server { - listen 80; - listen 443 ssl; - - ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt; - ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key; - - server_name localhost; - - location / { - root /usr/share/nginx/html; - index index.html index.htm; - try_files $uri $uri/ /index.html; - } - - error_page 404 /404.html; - location = /40x.html { - } - } -} diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/CleanAspire.WebApp.csproj b/src/CleanAspire.WebApp/CleanAspire.WebApp.csproj similarity index 62% rename from CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/CleanAspire.WebApp.csproj rename to src/CleanAspire.WebApp/CleanAspire.WebApp.csproj index fae3421..e6786b3 100644 --- a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/CleanAspire.WebApp.csproj +++ b/src/CleanAspire.WebApp/CleanAspire.WebApp.csproj @@ -1,13 +1,17 @@ - + net9.0 enable enable + aa04e12f-2328-4d88-a3b5-5b0dfc063bbe + Linux + ..\.. + diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Components/App.razor b/src/CleanAspire.WebApp/Components/App.razor similarity index 100% rename from CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Components/App.razor rename to src/CleanAspire.WebApp/Components/App.razor diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Components/Pages/Error.razor b/src/CleanAspire.WebApp/Components/Pages/Error.razor similarity index 100% rename from CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Components/Pages/Error.razor rename to src/CleanAspire.WebApp/Components/Pages/Error.razor diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Components/_Imports.razor b/src/CleanAspire.WebApp/Components/_Imports.razor similarity index 100% rename from CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Components/_Imports.razor rename to src/CleanAspire.WebApp/Components/_Imports.razor diff --git a/src/CleanAspire.WebApp/Dockerfile b/src/CleanAspire.WebApp/Dockerfile new file mode 100644 index 0000000..eed2e78 --- /dev/null +++ b/src/CleanAspire.WebApp/Dockerfile @@ -0,0 +1,61 @@ +# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. + +# This stage is used when running from VS in fast mode (Default for Debug configuration) +FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base +USER $APP_UID +WORKDIR /app + + + +# This stage is used to build the service project +FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["src/CleanAspire.WebApp/CleanAspire.WebApp.csproj", "src/CleanAspire.WebApp/"] +COPY ["src/CleanAspire.ClientApp/CleanAspire.ClientApp.csproj", "src/CleanAspire.ClientApp/"] +COPY ["src/CleanAspire.ServiceDefaults/CleanAspire.ServiceDefaults.csproj", "src/CleanAspire.ServiceDefaults/"] +RUN dotnet restore "./src/CleanAspire.WebApp/CleanAspire.WebApp.csproj" +COPY . . +WORKDIR "/src/src/CleanAspire.WebApp" +RUN dotnet build "./CleanAspire.WebApp.csproj" -c $BUILD_CONFIGURATION -o /app/build + +# This stage is used to publish the service project to be copied to the final stage +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "./CleanAspire.WebApp.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration) +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . + +# Install OpenSSL +RUN apt-get update && apt-get install -y openssl + +# Generate a self-signed certificate +RUN mkdir -p /app/https && \ + openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes \ + -keyout /app/https/private.key -out /app/https/certificate.crt \ + -subj "/C=US/ST=State/L=City/O=Organization/CN=localhost" && \ + openssl pkcs12 -export -out /app/https/aspnetapp.pfx \ + -inkey /app/https/private.key -in /app/https/certificate.crt \ + -password pass:CREDENTIAL_PLACEHOLDER + + +# Setup environment variables for the application to find the certificate +ENV ASPNETCORE_URLS=http://+:80;https://+:443 +ENV ASPNETCORE_Kestrel__Certificates__Default__Password="CREDENTIAL_PLACEHOLDER" +ENV ASPNETCORE_Kestrel__Certificates__Default__Path="/app/https/aspnetapp.pfx" + + +# Expose ports +EXPOSE 80 443 + +# Set the environment variable for ASP.NET Core to use Production settings +ENV ASPNETCORE_ENVIRONMENT=Development + +# Enable Service Worker for PWA Installation +COPY src/CleanAspire.ClientApp/wwwroot/service-worker.published.js wwwroot/service-worker.js +COPY src/CleanAspire.ClientApp/wwwroot/manifest.json wwwroot/manifest.json + +ENTRYPOINT ["dotnet", "CleanAspire.WebApp.dll"] \ No newline at end of file diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Program.cs b/src/CleanAspire.WebApp/Program.cs similarity index 100% rename from CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/Program.cs rename to src/CleanAspire.WebApp/Program.cs diff --git a/src/CleanAspire.WebApp/Properties/launchSettings.json b/src/CleanAspire.WebApp/Properties/launchSettings.json new file mode 100644 index 0000000..637b835 --- /dev/null +++ b/src/CleanAspire.WebApp/Properties/launchSettings.json @@ -0,0 +1,36 @@ +{ + "profiles": { + "http": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", + "applicationUrl": "http://localhost:5252" + }, + "https": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", + "applicationUrl": "https://localhost:7114;http://localhost:5252" + }, + "Container (Dockerfile)": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}", + "environmentVariables": { + "ASPNETCORE_HTTPS_PORTS": "8081", + "ASPNETCORE_HTTP_PORTS": "8080" + }, + "publishAllPorts": true, + "useSSL": true + } + }, + "$schema": "https://json.schemastore.org/launchsettings.json" +} \ No newline at end of file diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/appsettings.Development.json b/src/CleanAspire.WebApp/appsettings.Development.json similarity index 100% rename from CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/appsettings.Development.json rename to src/CleanAspire.WebApp/appsettings.Development.json diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/appsettings.json b/src/CleanAspire.WebApp/appsettings.json similarity index 100% rename from CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/appsettings.json rename to src/CleanAspire.WebApp/appsettings.json diff --git a/CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/wwwroot/app.css b/src/CleanAspire.WebApp/wwwroot/app.css similarity index 100% rename from CleanAspire.BlazorWebApp/CleanAspire.BlazorWebApp/wwwroot/app.css rename to src/CleanAspire.WebApp/wwwroot/app.css From 4490e01f15e3ea2ef9d49d024370b65ba134eaa8 Mon Sep 17 00:00:00 2001 From: hualin Date: Wed, 18 Dec 2024 13:30:12 +0800 Subject: [PATCH 03/15] Update Dockerfile --- src/CleanAspire.WebApp/Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CleanAspire.WebApp/Dockerfile b/src/CleanAspire.WebApp/Dockerfile index eed2e78..c3035b0 100644 --- a/src/CleanAspire.WebApp/Dockerfile +++ b/src/CleanAspire.WebApp/Dockerfile @@ -2,7 +2,6 @@ # This stage is used when running from VS in fast mode (Default for Debug configuration) FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base -USER $APP_UID WORKDIR /app From 4a91a47013ad3d72c52f10004a0f3071033839d9 Mon Sep 17 00:00:00 2001 From: hualin Date: Wed, 18 Dec 2024 13:35:55 +0800 Subject: [PATCH 04/15] commit --- src/CleanAspire.AppHost/CleanAspire.AppHost.csproj | 2 +- src/CleanAspire.WebApp/Dockerfile | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/CleanAspire.AppHost/CleanAspire.AppHost.csproj b/src/CleanAspire.AppHost/CleanAspire.AppHost.csproj index f366b5e..8443b97 100644 --- a/src/CleanAspire.AppHost/CleanAspire.AppHost.csproj +++ b/src/CleanAspire.AppHost/CleanAspire.AppHost.csproj @@ -15,7 +15,7 @@ - + diff --git a/src/CleanAspire.WebApp/Dockerfile b/src/CleanAspire.WebApp/Dockerfile index c3035b0..e3195db 100644 --- a/src/CleanAspire.WebApp/Dockerfile +++ b/src/CleanAspire.WebApp/Dockerfile @@ -1,11 +1,5 @@ # See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. -# This stage is used when running from VS in fast mode (Default for Debug configuration) -FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base -WORKDIR /app - - - # This stage is used to build the service project FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build ARG BUILD_CONFIGURATION=Release @@ -24,7 +18,7 @@ ARG BUILD_CONFIGURATION=Release RUN dotnet publish "./CleanAspire.WebApp.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false # This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration) -FROM base AS final +FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS final WORKDIR /app COPY --from=publish /app/publish . @@ -51,7 +45,7 @@ ENV ASPNETCORE_Kestrel__Certificates__Default__Path="/app/https/aspnetapp.pfx" EXPOSE 80 443 # Set the environment variable for ASP.NET Core to use Production settings -ENV ASPNETCORE_ENVIRONMENT=Development +ENV ASPNETCORE_ENVIRONMENT=Production # Enable Service Worker for PWA Installation COPY src/CleanAspire.ClientApp/wwwroot/service-worker.published.js wwwroot/service-worker.js From 6d6f950804e2ed93f794adada3b6b2af85a583c9 Mon Sep 17 00:00:00 2001 From: hualin Date: Wed, 18 Dec 2024 13:38:08 +0800 Subject: [PATCH 05/15] Update docker.yml --- .github/workflows/docker.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index e09d1e6..0edcb7a 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -32,10 +32,10 @@ jobs: password: ${{ secrets.DOCKER_PASSWORD }} - - name: Build and push CleanAspire.ClientApp image + - name: Build and push CleanAspire.WebApp image run: | - docker build -t ${{ secrets.DOCKER_USERNAME }}/cleanaspire-clientapp:${{ steps.version.outputs.version }} -f src/CleanAspire.ClientApp/Dockerfile . - docker push ${{ secrets.DOCKER_USERNAME }}/cleanaspire-clientapp:${{ steps.version.outputs.version }} + docker build -t ${{ secrets.DOCKER_USERNAME }}/cleanaspire-webapp:${{ steps.version.outputs.version }} -f src/CleanAspire.WebApp/Dockerfile . + docker push ${{ secrets.DOCKER_USERNAME }}/cleanaspire-webapp:${{ steps.version.outputs.version }} - name: Build and push CleanAspire.Api image run: | From e3b0aba6a049b00c3b34feda79acef64478ed348 Mon Sep 17 00:00:00 2001 From: hualin Date: Wed, 18 Dec 2024 13:43:08 +0800 Subject: [PATCH 06/15] Update Dockerfile --- src/CleanAspire.WebApp/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CleanAspire.WebApp/Dockerfile b/src/CleanAspire.WebApp/Dockerfile index e3195db..823d083 100644 --- a/src/CleanAspire.WebApp/Dockerfile +++ b/src/CleanAspire.WebApp/Dockerfile @@ -48,7 +48,7 @@ EXPOSE 80 443 ENV ASPNETCORE_ENVIRONMENT=Production # Enable Service Worker for PWA Installation -COPY src/CleanAspire.ClientApp/wwwroot/service-worker.published.js wwwroot/service-worker.js -COPY src/CleanAspire.ClientApp/wwwroot/manifest.json wwwroot/manifest.json +# COPY src/CleanAspire.ClientApp/wwwroot/service-worker.published.js wwwroot/service-worker.js +# COPY src/CleanAspire.ClientApp/wwwroot/manifest.json wwwroot/manifest.json ENTRYPOINT ["dotnet", "CleanAspire.WebApp.dll"] \ No newline at end of file From 823698845e32f17c4910fefe986e53c7572694a6 Mon Sep 17 00:00:00 2001 From: hualin Date: Wed, 18 Dec 2024 13:47:53 +0800 Subject: [PATCH 07/15] Update WebTests.cs --- tests/CleanAspire.Tests/WebTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/CleanAspire.Tests/WebTests.cs b/tests/CleanAspire.Tests/WebTests.cs index 7e01632..94d257c 100644 --- a/tests/CleanAspire.Tests/WebTests.cs +++ b/tests/CleanAspire.Tests/WebTests.cs @@ -1,4 +1,4 @@ -namespace CleanAspire.Tests; +namespace CleanAspire.Tests; public class WebTests { @@ -17,8 +17,8 @@ public async Task GetWebResourceRootReturnsOkStatusCode() await app.StartAsync(); // Act - var httpClient = app.CreateHttpClient("webfrontend"); - await resourceNotificationService.WaitForResourceAsync("webfrontend", KnownResourceStates.Running).WaitAsync(TimeSpan.FromSeconds(30)); + var httpClient = app.CreateHttpClient("blazorweb"); + await resourceNotificationService.WaitForResourceAsync("blazorweb", KnownResourceStates.Running).WaitAsync(TimeSpan.FromSeconds(30)); var response = await httpClient.GetAsync("/"); // Assert From a5df2e0fda091d627066f51ec7948fc44f0040a7 Mon Sep 17 00:00:00 2001 From: hualin Date: Wed, 18 Dec 2024 17:12:01 +0800 Subject: [PATCH 08/15] Update dotnet.yml --- .github/workflows/dotnet.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 371c628..14c3531 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -12,6 +12,10 @@ jobs: runs-on: ubuntu-latest steps: + # Install CA certificates to ensure SSL trust + - name: Install CA Certificates + run: sudo apt-get update && sudo apt-get install -y ca-certificates + - uses: actions/checkout@v4 - name: Setup .NET uses: actions/setup-dotnet@v4 From 7701d26f66d2327f98e1659c753f6075acd6ba7d Mon Sep 17 00:00:00 2001 From: hualin Date: Wed, 18 Dec 2024 17:15:42 +0800 Subject: [PATCH 09/15] Update dotnet.yml --- .github/workflows/dotnet.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 14c3531..1ee9a8e 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -15,12 +15,17 @@ jobs: # Install CA certificates to ensure SSL trust - name: Install CA Certificates run: sudo apt-get update && sudo apt-get install -y ca-certificates - + - uses: actions/checkout@v4 - name: Setup .NET uses: actions/setup-dotnet@v4 with: dotnet-version: 9.0.x + + # Trust the ASP.NET Core development certificate + - name: Trust ASP.NET Core HTTPS Development Certificate + run: dotnet dev-certs https --trust + - name: Restore dependencies run: dotnet restore CleanAspire.sln - name: Build From c99e6b717e1141c050392787b3d005009e6e2bca Mon Sep 17 00:00:00 2001 From: hualin Date: Wed, 18 Dec 2024 17:23:36 +0800 Subject: [PATCH 10/15] Update Program.cs --- src/CleanAspire.ClientApp/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CleanAspire.ClientApp/Program.cs b/src/CleanAspire.ClientApp/Program.cs index 43ae928..c281006 100644 --- a/src/CleanAspire.ClientApp/Program.cs +++ b/src/CleanAspire.ClientApp/Program.cs @@ -81,10 +81,10 @@ builder.Configuration.Bind("Local", options.ProviderOptions); }); // register the custom state provider -builder.Services.AddScoped(); +builder.Services.AddSingleton(); // register the account management interface -builder.Services.AddScoped( +builder.Services.AddSingleton( sp => (ISignInManagement)sp.GetRequiredService()); From 1de7b9388be88857746cce4bf32024b336007f9e Mon Sep 17 00:00:00 2001 From: "hualin.zhu" Date: Wed, 18 Dec 2024 18:21:30 +0800 Subject: [PATCH 11/15] Update index.html --- src/CleanAspire.ClientApp/wwwroot/index.html | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CleanAspire.ClientApp/wwwroot/index.html b/src/CleanAspire.ClientApp/wwwroot/index.html index 8758b71..94ac834 100644 --- a/src/CleanAspire.ClientApp/wwwroot/index.html +++ b/src/CleanAspire.ClientApp/wwwroot/index.html @@ -8,7 +8,6 @@ - From 8aa3d968c90e429cc5638c03e23f4ee4eb8c2486 Mon Sep 17 00:00:00 2001 From: "hualin.zhu" Date: Wed, 18 Dec 2024 18:35:36 +0800 Subject: [PATCH 12/15] readme --- README.md | 16 +++++++++++----- .../wwwroot/appsettings.Development.json | 2 +- .../wwwroot/appsettings.json | 2 +- .../appsettings.Development.json | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3214ddc..ef4ff1b 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ By incorporating robust offline capabilities, CleanAspire empowers developers to version: '3.8' services: apiservice: - image: blazordevlab/cleanaspire-api:0.0.50 + image: blazordevlab/cleanaspire-api:0.0.51 environment: - ASPNETCORE_ENVIRONMENT=Development - AllowedHosts=* @@ -107,11 +107,17 @@ services: - "8018:443" - webfrontend: - image: blazordevlab/cleanaspire-clientapp:0.0.50 + blazorweb: + image: blazordevlab/cleanaspire-webapp:0.0.51 + environment: + - ASPNETCORE_ENVIRONMENT=Production + - AllowedHosts=* + - ASPNETCORE_URLS=http://+:80;https://+:443 + - ASPNETCORE_HTTP_PORTS=80 + - ASPNETCORE_HTTPS_PORTS=443 ports: - - "8016:80" - - "8017:443" + - "8015:80" + - "8014:443" diff --git a/src/CleanAspire.ClientApp/wwwroot/appsettings.Development.json b/src/CleanAspire.ClientApp/wwwroot/appsettings.Development.json index fa07868..b4ab680 100644 --- a/src/CleanAspire.ClientApp/wwwroot/appsettings.Development.json +++ b/src/CleanAspire.ClientApp/wwwroot/appsettings.Development.json @@ -7,7 +7,7 @@ }, "ClientAppSettings": { "AppName": "Progressive Web Application", - "Version": "v0.0.50", + "Version": "v0.0.51", "ServiceBaseUrl": "https://localhost:7341" } } diff --git a/src/CleanAspire.ClientApp/wwwroot/appsettings.json b/src/CleanAspire.ClientApp/wwwroot/appsettings.json index 89d5b6b..2349092 100644 --- a/src/CleanAspire.ClientApp/wwwroot/appsettings.json +++ b/src/CleanAspire.ClientApp/wwwroot/appsettings.json @@ -7,7 +7,7 @@ }, "ClientAppSettings": { "AppName": "Progressive Web Application", - "Version": "v0.0.50", + "Version": "v0.0.51", "ServiceBaseUrl": "https://apiservice.blazorserver.com" } } diff --git a/src/CleanAspire.WebApp/appsettings.Development.json b/src/CleanAspire.WebApp/appsettings.Development.json index fa07868..b4ab680 100644 --- a/src/CleanAspire.WebApp/appsettings.Development.json +++ b/src/CleanAspire.WebApp/appsettings.Development.json @@ -7,7 +7,7 @@ }, "ClientAppSettings": { "AppName": "Progressive Web Application", - "Version": "v0.0.50", + "Version": "v0.0.51", "ServiceBaseUrl": "https://localhost:7341" } } From bb9159c2bc4fbf1ae5589f300b406dc861646c5f Mon Sep 17 00:00:00 2001 From: "hualin.zhu" Date: Wed, 18 Dec 2024 19:37:16 +0800 Subject: [PATCH 13/15] commit --- src/CleanAspire.Api/CleanAspire.Api.csproj | 2 +- .../wwwroot/service-worker.published.js | 11 ++++++++--- src/CleanAspire.WebApp/appsettings.json | 2 +- src/CleanAspire.WebApp/wwwroot/app.css | 1 + 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/CleanAspire.Api/CleanAspire.Api.csproj b/src/CleanAspire.Api/CleanAspire.Api.csproj index 187a1f4..5b72650 100644 --- a/src/CleanAspire.Api/CleanAspire.Api.csproj +++ b/src/CleanAspire.Api/CleanAspire.Api.csproj @@ -16,7 +16,7 @@ - + diff --git a/src/CleanAspire.ClientApp/wwwroot/service-worker.published.js b/src/CleanAspire.ClientApp/wwwroot/service-worker.published.js index aae59f0..4cd9291 100644 --- a/src/CleanAspire.ClientApp/wwwroot/service-worker.published.js +++ b/src/CleanAspire.ClientApp/wwwroot/service-worker.published.js @@ -24,6 +24,11 @@ async function onInstall(event) { .filter(asset => offlineAssetsInclude.some(pattern => pattern.test(asset.url))) .filter(asset => !offlineAssetsExclude.some(pattern => pattern.test(asset.url))) .map(asset => new Request(asset.url, { integrity: asset.hash, cache: 'no-cache' })); + + // Also cache the host HTML and blazor.web.js + assetsRequests.push(new Request(baseUrl, { cache: 'no-cache' })); + assetsRequests.push(new Request(new URL('_framework/blazor.web.js', baseUrl).href, { cache: 'no-cache' })); + await caches.open(cacheName).then(cache => cache.addAll(assetsRequests)); } @@ -40,13 +45,13 @@ async function onActivate(event) { async function onFetch(event) { let cachedResponse = null; if (event.request.method === 'GET') { - // For all navigation requests, try to serve index.html from cache, + // For all navigation requests, try to serve the host HTML from cache, // unless that request is for an offline resource. // If you need some URLs to be server-rendered, edit the following check to exclude those URLs - const shouldServeIndexHtml = event.request.mode === 'navigate' + const shouldServeHostHtml = event.request.mode === 'navigate' && !manifestUrlList.some(url => url === event.request.url); - const request = shouldServeIndexHtml ? 'index.html' : event.request; + const request = shouldServeHostHtml ? baseUrl : event.request; const cache = await caches.open(cacheName); cachedResponse = await cache.match(request); } diff --git a/src/CleanAspire.WebApp/appsettings.json b/src/CleanAspire.WebApp/appsettings.json index e5058b9..7bcc835 100644 --- a/src/CleanAspire.WebApp/appsettings.json +++ b/src/CleanAspire.WebApp/appsettings.json @@ -8,7 +8,7 @@ "AllowedHosts": "*", "ClientAppSettings": { "AppName": "Progressive Web Application", - "Version": "v0.0.50", + "Version": "v0.0.51", "ServiceBaseUrl": "https://apiservice.blazorserver.com" } } diff --git a/src/CleanAspire.WebApp/wwwroot/app.css b/src/CleanAspire.WebApp/wwwroot/app.css index 5388357..771f127 100644 --- a/src/CleanAspire.WebApp/wwwroot/app.css +++ b/src/CleanAspire.WebApp/wwwroot/app.css @@ -1,3 +1,4 @@ + h1:focus { outline: none; } From 429c95c5be120eb95cb4878a090809bf295240a1 Mon Sep 17 00:00:00 2001 From: "hualin.zhu" Date: Wed, 18 Dec 2024 20:17:19 +0800 Subject: [PATCH 14/15] remove ImportMap --- src/CleanAspire.WebApp/Components/App.razor | 1 - src/CleanAspire.WebApp/Program.cs | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/CleanAspire.WebApp/Components/App.razor b/src/CleanAspire.WebApp/Components/App.razor index 4155de4..d8dfb98 100644 --- a/src/CleanAspire.WebApp/Components/App.razor +++ b/src/CleanAspire.WebApp/Components/App.razor @@ -11,7 +11,6 @@ - diff --git a/src/CleanAspire.WebApp/Program.cs b/src/CleanAspire.WebApp/Program.cs index 6e4d083..b2808eb 100644 --- a/src/CleanAspire.WebApp/Program.cs +++ b/src/CleanAspire.WebApp/Program.cs @@ -21,13 +21,16 @@ var builder = WebApplication.CreateBuilder(args); builder.AddServiceDefaults(); + + + // Add services to the container. builder.Services.AddRazorComponents() .AddInteractiveServerComponents() .AddInteractiveWebAssemblyComponents(); - + // register the cookie handler builder.Services.AddTransient(); builder.Services.AddTransient(); From 3eb20566d6d359df4af1945fb3b0739b7155adce Mon Sep 17 00:00:00 2001 From: "hualin.zhu" Date: Wed, 18 Dec 2024 20:24:56 +0800 Subject: [PATCH 15/15] Update App.razor --- src/CleanAspire.WebApp/Components/App.razor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CleanAspire.WebApp/Components/App.razor b/src/CleanAspire.WebApp/Components/App.razor index d8dfb98..d5cd9a0 100644 --- a/src/CleanAspire.WebApp/Components/App.razor +++ b/src/CleanAspire.WebApp/Components/App.razor @@ -11,13 +11,13 @@ + -