Skip to content

Commit

Permalink
Merge pull request #22 from neozhu/feature/autorendermode
Browse files Browse the repository at this point in the history
Migrate from Blazor WebAssembly to Blazor Web App with AutoRenderMode Support
  • Loading branch information
neozhu authored Dec 18, 2024
2 parents 64042ff + 3eb2056 commit 0bedb6a
Show file tree
Hide file tree
Showing 32 changed files with 530 additions and 103 deletions.
30 changes: 30 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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/**
6 changes: 3 additions & 3 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,20 @@ 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
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
Expand Down
7 changes: 7 additions & 0 deletions CleanAspire.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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", "src\CleanAspire.WebApp\CleanAspire.WebApp.csproj", "{E29307F2-485B-47B4-9CA7-A7EA6949134B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -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
Expand All @@ -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}
Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=*
Expand All @@ -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"



Expand Down
2 changes: 1 addition & 1 deletion src/CleanAspire.Api/CleanAspire.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageReference Include="Microsoft.Extensions.ApiDescription.Server" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="9.0.0" />
<PackageReference Include="Scalar.AspNetCore" Version="1.2.61" />
<PackageReference Include="Scalar.AspNetCore" Version="1.2.63" />
<PackageReference Include="Scrutor" Version="5.0.2" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.6" />
<PackageReference Include="StrongGrid" Version="0.110.0" />
Expand Down
2 changes: 1 addition & 1 deletion src/CleanAspire.Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/CleanAspire.AppHost/CleanAspire.AppHost.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<Sdk Name="Aspire.AppHost.Sdk" Version="9.0.0" />

Expand All @@ -15,8 +15,8 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\CleanAspire.WebApp\CleanAspire.WebApp.csproj" />
<ProjectReference Include="..\CleanAspire.Api\CleanAspire.Api.csproj" />
<ProjectReference Include="..\CleanAspire.ClientApp\CleanAspire.ClientApp.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/CleanAspire.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var apiService = builder.AddProject<Projects.CleanAspire_Api>("apiservice");

builder.AddProject<Projects.CleanAspire_ClientApp>("webfrontend")
builder.AddProject<Projects.CleanAspire_WebApp>("blazorweb")
.WithExternalHttpEndpoints()
.WithReference(apiService)
.WaitFor(apiService);
Expand Down
2 changes: 2 additions & 0 deletions src/CleanAspire.ClientApp/CleanAspire.ClientApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
<StaticWebAssetProjectMode>Default</StaticWebAssetProjectMode>
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
<RootNamespace>CleanAspire.ClientApp</RootNamespace>
<AssemblyName>CleanAspire.ClientApp</AssemblyName>
Expand Down
33 changes: 33 additions & 0 deletions src/CleanAspire.ClientApp/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IStorageService, LocalStorageService>();
services.AddScoped<IUserPreferencesService, UserPreferencesService>();
services.AddScoped<LayoutService>();
services.AddScoped<DialogServiceHelper>();
#endregion
}
public static void TryAddMudBlazor(this IServiceCollection services, IConfiguration config)
{
#region register MudBlazor.Services
Expand Down
42 changes: 0 additions & 42 deletions src/CleanAspire.ClientApp/Dockerfile

This file was deleted.

6 changes: 4 additions & 2 deletions src/CleanAspire.ClientApp/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
{
LayoutService.MajorUpdateOccurred += LayoutServiceOnMajorUpdateOccured;
}
OnlineStatusInterop.Initialize();
await OfflineModeState.InitializeAsync();


}

protected override async Task OnAfterRenderAsync(bool firstRender)
Expand All @@ -31,6 +31,8 @@

if (firstRender)
{
OnlineStatusInterop.Initialize();
await OfflineModeState.InitializeAsync();
await ApplyUserPreferences();
if (_mudThemeProvider != null)
{
Expand Down
8 changes: 4 additions & 4 deletions src/CleanAspire.ClientApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

var builder = WebAssemblyHostBuilder.CreateDefault(args);

builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
//builder.RootComponents.Add<App>("#app");
//builder.RootComponents.Add<HeadOutlet>("head::after");

// register the cookie handler
builder.Services.AddTransient<CookieHandler>();
Expand Down Expand Up @@ -81,10 +81,10 @@
builder.Configuration.Bind("Local", options.ProviderOptions);
});
// register the custom state provider
builder.Services.AddScoped<AuthenticationStateProvider, CookieAuthenticationStateProvider>();
builder.Services.AddSingleton<AuthenticationStateProvider, CookieAuthenticationStateProvider>();

// register the account management interface
builder.Services.AddScoped(
builder.Services.AddSingleton(
sp => (ISignInManagement)sp.GetRequiredService<AuthenticationStateProvider>());


Expand Down
12 changes: 12 additions & 0 deletions src/CleanAspire.ClientApp/Routes.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public override async Task<AuthenticationState> GetAuthenticationStateAsync()
var indexedDb = serviceProvider.GetRequiredService<IndexedDbCache>();
var onlineStatusInterop = serviceProvider.GetRequiredService<OnlineStatusInterop>();
var offlineState = serviceProvider.GetRequiredService<OfflineModeState>();
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)
{
Expand Down Expand Up @@ -78,9 +78,9 @@ public async Task LoginAsync(LoginRequest request, bool remember = true, Cancell
var indexedDb = serviceProvider.GetRequiredService<IndexedDbCache>();
var onlineStatusInterop = serviceProvider.GetRequiredService<OnlineStatusInterop>();
var offlineState = serviceProvider.GetRequiredService<OfflineModeState>();
bool offlineModel = offlineState.Enabled;
try
{
bool offlineModel = offlineState.Enabled;
var isOnline = await onlineStatusInterop.GetOnlineStatusAsync();
if (isOnline)
{
Expand Down
31 changes: 0 additions & 31 deletions src/CleanAspire.ClientApp/nginx.conf

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"ClientAppSettings": {
"AppName": "Progressive Web Application",
"Version": "v0.0.50",
"Version": "v0.0.51",
"ServiceBaseUrl": "https://localhost:7341"
}
}
2 changes: 1 addition & 1 deletion src/CleanAspire.ClientApp/wwwroot/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"ClientAppSettings": {
"AppName": "Progressive Web Application",
"Version": "v0.0.50",
"Version": "v0.0.51",
"ServiceBaseUrl": "https://apiservice.blazorserver.com"
}
}
Loading

0 comments on commit 0bedb6a

Please sign in to comment.