Skip to content

Commit

Permalink
Prepare Blazor Server
Browse files Browse the repository at this point in the history
  • Loading branch information
usercode committed Apr 18, 2024
1 parent 15df966 commit 433acf3
Show file tree
Hide file tree
Showing 83 changed files with 1,204 additions and 558 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,7 @@ if (env.IsDevelopment())
app.UseWebAssemblyDebugging();
}

app.UseDragonFly(x => x
.MapImageWizard()
.MapApiKey()
.MapIdentity()
.MapRestApi());
app.UseDragonFly();
app.UseDragonFlyManager();
app.UseRouting();
app.Run();
Expand All @@ -231,7 +227,7 @@ var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<DragonFly.App.Client.App>("app");

//Register DragonFly components
builder.AddDragonFly()
builder.AddDragonFlyClient()
.AddRestApi()
.AddBlockField()
.AddIdentity()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// MIT License

using System.Net.Http.Json;
using DragonFly.Query;

namespace DragonFly.API.Client;

Expand All @@ -12,6 +11,8 @@ namespace DragonFly.API.Client;
/// </summary>
public partial class ClientContentService : IBackgroundTaskService
{
public event Func<BackgroundTaskStatusChange, IBackgroundTaskInfo, Task> BackgroundTaskChanged;

public async Task<IBackgroundTaskInfo[]> GetTasksAsync()
{
var response = await Client.PostAsync("api/task/query", new StringContent(string.Empty));
Expand Down
9 changes: 2 additions & 7 deletions src/DragonFly.API/Extensions/DragonFlyBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,9 @@ public static IDragonFlyBuilder AddRestApi(this IDragonFlyBuilder builder)

builder.AddRestApiCore();

return builder;
}

public static IDragonFlyMiddlewareBuilder MapRestApi(this IDragonFlyMiddlewareBuilder builder)
{
builder.Endpoints(endpoints =>
builder.AddEndpoint(x =>
{
RouteGroupBuilder group = endpoints.MapGroup("api")
RouteGroupBuilder group = x.MapGroup("api")
.RequirePermission()
.WithDisplayName("DragonFly.API");
Expand Down
3 changes: 2 additions & 1 deletion src/DragonFly.ApiKeys.Client/DragonFlyBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using DragonFly.ApiKeys.Razor.Services;
using DragonFly.ApiKeys.Client;
using DragonFly.Client.Builders;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace DragonFly.Client;

Expand All @@ -16,7 +17,7 @@ public static IDragonFlyBuilder AddApiKeys(this IDragonFlyBuilder builder)
{
builder.AddRazorRouting();

builder.Services.AddTransient<IApiKeyService, ApiKeyService>();
builder.Services.TryAddTransient<IApiKeyService, ApiKeyService>();

builder.Init<ApiKeyInitializer>();

Expand Down
4 changes: 2 additions & 2 deletions src/DragonFly.ApiKeys/DragonFly.ApiKeys.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.24.0" />
<PackageReference Include="MongoDB.Driver.GridFS" Version="2.24.0" />
<PackageReference Include="MongoDB.Driver" Version="2.25.0" />
<PackageReference Include="MongoDB.Driver.GridFS" Version="2.25.0" />
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 2 additions & 7 deletions src/DragonFly.ApiKeys/DragonFlyBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static IDragonFlyBuilder AddApiKeys(this IDragonFlyBuilder builder)
builder.Services.AddSingleton<MongoIdentityStore>();
builder.Services.AddSingleton<IAuthorizationHandler, PermissionHandler>();

builder.Authentication.AddApiKey(ApiKeyAuthenticationDefaults.AuthenticationScheme);
builder.Services.AddAuthentication().AddApiKey(ApiKeyAuthenticationDefaults.AuthenticationScheme);

builder.AddPermissionScheme(ApiKeyAuthenticationDefaults.AuthenticationScheme);

Expand All @@ -38,12 +38,7 @@ public static IDragonFlyBuilder AddApiKeys(this IDragonFlyBuilder builder)
.Add(ApiKeyPermissions.DeleteApiKey);
});

return builder;
}

public static IDragonFlyMiddlewareBuilder MapApiKey(this IDragonFlyMiddlewareBuilder builder)
{
builder.Endpoints(x => x.MapApiKeyApi());
builder.AddEndpoint(x => x.MapApiKeyApi());

return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace DragonFly.ApiKeys.AspNetCore.Middlewares;

static class ApiKeysExtensions
{
public static void MapApiKeyApi(this IDragonFlyEndpointBuilder endpoints)
public static IEndpointConventionBuilder MapApiKeyApi(this IEndpointRouteBuilder endpoints)
{
RouteGroupBuilder group = endpoints.MapGroup("api/apikey");

Expand All @@ -23,6 +23,8 @@ public static void MapApiKeyApi(this IDragonFlyEndpointBuilder endpoints)
group.MapPost("", MapCreate).RequirePermission(ApiKeyPermissions.CreateApiKey);
group.MapPut("", MapUpdate).RequirePermission(ApiKeyPermissions.UpdateApiKey);
group.MapDelete("{id:guid}", MapDelete).RequirePermission(ApiKeyPermissions.DeleteApiKey);

return group;
}

private static async Task<Results<Ok<ApiKey>, NotFound>> MapGet(Guid id, IApiKeyService service)
Expand Down
22 changes: 22 additions & 0 deletions src/DragonFly.App.Server/Components/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>DragonFly</title>
<base href="/manager/" />
<link href="/_content/DragonFly.Client/css/bootstrap.min.css" rel="stylesheet" />
<link href="/_content/DragonFly.Client/css/all.min.css" rel="stylesheet" />
<link href="/_content/DragonFly.Client/lib/font-awesome/css/all.min.css" rel="stylesheet" />
<script src="/_content/BlazorStrap/blazorstrap.js"></script>
<script src="/_content/DragonFly.Client/lib/tinymce/tinymce.min.js"></script>
<script src="/_content/TinyMCE.Blazor/tinymce-blazor.js"></script>
<HeadOutlet @rendermode="InteractiveServer" />
</head>
<body>
<app>
<Routes @rendermode="InteractiveServer" />
</app>
<script src="_framework/blazor.web.js"></script>
</body>
</html>
File renamed without changes.
12 changes: 12 additions & 0 deletions src/DragonFly.App.Server/Components/_Imports.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@using System.Net.Http
@using System.Net.Http.Json
@using Microsoft.AspNetCore.Components.Authorization
@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 DragonFly.Client
@using DragonFly.Client.Shared
@using DragonFly.Identity.Client.Logins
20 changes: 7 additions & 13 deletions src/DragonFly.App.Server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,21 @@ FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["DragonFly.App.Server/DragonFly.App.Server.csproj", "DragonFly.App.Server/"]
COPY ["DragonFly.API/DragonFly.API.csproj", "DragonFly.API/"]
COPY ["DragonFly.API.Core/DragonFly.API.Core.csproj", "DragonFly.API.Core/"]
COPY ["DragonFly.AspNetCore/DragonFly.AspNetCore.csproj", "DragonFly.AspNetCore/"]
COPY ["DragonFly.Core/DragonFly.Core.csproj", "DragonFly.Core/"]
COPY ["DragonFly.Generator/DragonFly.Generator.csproj", "DragonFly.Generator/"]
COPY ["DragonFly.AspNetCore/DragonFly.AspNetCore.csproj", "DragonFly.AspNetCore/"]
COPY ["DragonFly.App.Client/DragonFly.App.Client.csproj", "DragonFly.App.Client/"]
COPY ["DragonFly.Client/DragonFly.Client.csproj", "DragonFly.Client/"]
COPY ["DragonFly.API.Client/DragonFly.API.Client.csproj", "DragonFly.API.Client/"]
COPY ["DragonFly.ApiKeys.Client/DragonFly.ApiKeys.Client.csproj", "DragonFly.ApiKeys.Client/"]
COPY ["DragonFly.ApiKeys/DragonFly.ApiKeys.csproj", "DragonFly.ApiKeys/"]
COPY ["DragonFly.ApiKeys.Core/DragonFly.ApiKeys.Core.csproj", "DragonFly.ApiKeys.Core/"]
COPY ["DragonFly.BlockField.Client/DragonFly.BlockField.Client.csproj", "DragonFly.BlockField.Client/"]
COPY ["DragonFly.BlockField.Core/DragonFly.BlockField.Core.csproj", "DragonFly.BlockField.Core/"]
COPY ["DragonFly.Identity.Client/DragonFly.Identity.Client.csproj", "DragonFly.Identity.Client/"]
COPY ["DragonFly.API.Core/DragonFly.API.Core.csproj", "DragonFly.API.Core/"]
COPY ["DragonFly.ApiKeys.Client/DragonFly.ApiKeys.Client.csproj", "DragonFly.ApiKeys.Client/"]
COPY ["DragonFly.Identity/DragonFly.Identity.csproj", "DragonFly.Identity/"]
COPY ["DragonFly.Identity.Core/DragonFly.Identity.Core.csproj", "DragonFly.Identity.Core/"]
COPY ["DragonFly.BlockField/DragonFly.BlockField.csproj", "DragonFly.BlockField/"]
COPY ["DragonFly.Identity.Client/DragonFly.Identity.Client.csproj", "DragonFly.Identity.Client/"]
COPY ["DragonFly.ImageWizard/DragonFly.ImageWizard.csproj", "DragonFly.ImageWizard/"]
COPY ["DragonFly.MongoDB/DragonFly.MongoDB.csproj", "DragonFly.MongoDB/"]
COPY ["DragonFly.Identity/DragonFly.Identity.csproj", "DragonFly.Identity/"]
COPY ["DragonFly.ApiKeys/DragonFly.ApiKeys.csproj", "DragonFly.ApiKeys/"]
COPY ["DragonFly.SampleData/DragonFly.SampleData.csproj", "DragonFly.SampleData/"]
RUN dotnet restore "./DragonFly.App.Server/./DragonFly.App.Server.csproj"
RUN dotnet restore "./DragonFly.App.Server/DragonFly.App.Server.csproj"
COPY . .
WORKDIR "/src/DragonFly.App.Server"
RUN dotnet build "./DragonFly.App.Server.csproj" -c $BUILD_CONFIGURATION -o /app/build
Expand Down
45 changes: 45 additions & 0 deletions src/DragonFly.App.Server/Dockerfile.original
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#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.

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["DragonFly.App.Server/DragonFly.App.Server.csproj", "DragonFly.App.Server/"]
COPY ["DragonFly.API/DragonFly.API.csproj", "DragonFly.API/"]
COPY ["DragonFly.API.Core/DragonFly.API.Core.csproj", "DragonFly.API.Core/"]
COPY ["DragonFly.Core/DragonFly.Core.csproj", "DragonFly.Core/"]
COPY ["DragonFly.Generator/DragonFly.Generator.csproj", "DragonFly.Generator/"]
COPY ["DragonFly.AspNetCore/DragonFly.AspNetCore.csproj", "DragonFly.AspNetCore/"]
COPY ["DragonFly.App.Client/DragonFly.App.Client.csproj", "DragonFly.App.Client/"]
COPY ["DragonFly.Client/DragonFly.Client.csproj", "DragonFly.Client/"]
COPY ["DragonFly.API.Client/DragonFly.API.Client.csproj", "DragonFly.API.Client/"]
COPY ["DragonFly.ApiKeys.Client/DragonFly.ApiKeys.Client.csproj", "DragonFly.ApiKeys.Client/"]
COPY ["DragonFly.ApiKeys.Core/DragonFly.ApiKeys.Core.csproj", "DragonFly.ApiKeys.Core/"]
COPY ["DragonFly.BlockField.Client/DragonFly.BlockField.Client.csproj", "DragonFly.BlockField.Client/"]
COPY ["DragonFly.BlockField.Core/DragonFly.BlockField.Core.csproj", "DragonFly.BlockField.Core/"]
COPY ["DragonFly.Identity.Client/DragonFly.Identity.Client.csproj", "DragonFly.Identity.Client/"]
COPY ["DragonFly.Identity.Core/DragonFly.Identity.Core.csproj", "DragonFly.Identity.Core/"]
COPY ["DragonFly.BlockField/DragonFly.BlockField.csproj", "DragonFly.BlockField/"]
COPY ["DragonFly.ImageWizard/DragonFly.ImageWizard.csproj", "DragonFly.ImageWizard/"]
COPY ["DragonFly.MongoDB/DragonFly.MongoDB.csproj", "DragonFly.MongoDB/"]
COPY ["DragonFly.Identity/DragonFly.Identity.csproj", "DragonFly.Identity/"]
COPY ["DragonFly.ApiKeys/DragonFly.ApiKeys.csproj", "DragonFly.ApiKeys/"]
COPY ["DragonFly.SampleData/DragonFly.SampleData.csproj", "DragonFly.SampleData/"]
RUN dotnet restore "./DragonFly.App.Server/./DragonFly.App.Server.csproj"
COPY . .
WORKDIR "/src/DragonFly.App.Server"
RUN dotnet build "./DragonFly.App.Server.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./DragonFly.App.Server.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "DragonFly.App.Server.dll"]
17 changes: 9 additions & 8 deletions src/DragonFly.App.Server/DragonFly.App.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,26 @@
<ItemGroup>
<None Remove="FileCache\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DragonFly.API\DragonFly.API.csproj" />
<ProjectReference Include="..\DragonFly.App.Client\DragonFly.App.Client.csproj" />
<ProjectReference Include="..\DragonFly.AspNetCore\DragonFly.AspNetCore.csproj" />
<ProjectReference Include="..\DragonFly.ImageWizard\DragonFly.ImageWizard.csproj" />
<ProjectReference Include="..\DragonFly.MongoDB\DragonFly.MongoDB.csproj" />
<ProjectReference Include="..\DragonFly.Identity\DragonFly.Identity.csproj" />
<ProjectReference Include="..\DragonFly.Client\DragonFly.Client.csproj" />
<ProjectReference Include="..\DragonFly.ApiKeys\DragonFly.ApiKeys.csproj" />
<ProjectReference Include="..\DragonFly.ApiKeys.Client\DragonFly.ApiKeys.Client.csproj" />
<ProjectReference Include="..\DragonFly.Identity\DragonFly.Identity.csproj" />
<ProjectReference Include="..\DragonFly.Identity.Client\DragonFly.Identity.Client.csproj" />
<ProjectReference Include="..\DragonFly.ImageWizard\DragonFly.ImageWizard.csproj" />
<ProjectReference Include="..\DragonFly.MongoDB\DragonFly.MongoDB.csproj" />
<ProjectReference Include="..\DragonFly.SampleData\DragonFly.SampleData.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DragonFly.Generator\DragonFly.Generator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\DragonFly.Generator\DragonFly.Generator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

</Project>
34 changes: 21 additions & 13 deletions src/DragonFly.App.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
// MIT License

using System;
using System.Linq;
using System.Threading.Tasks;
using DragonFly;
using DragonFly.API;
using DragonFly.App.Server.Components;
using DragonFly.AspNetCore;
using DragonFly.Client;
using DragonFly.MongoDB;
using DragonFlyABC;
using DragonFlyTEST;
using FFMpegCore;
using ImageWizard;
using ImageWizard.Caches;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Server;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Server.Kestrel.Core;
Expand Down Expand Up @@ -60,7 +65,6 @@
//DragonFly services
builder.Services.AddDragonFly()
.AddImageWizard()
.AddRestApi()
.AddMongoDbStorage()
.AddMongoDbIdentity()
.AddApiKeys()
Expand All @@ -71,8 +75,16 @@
.Init(x =>
{
})
;
});

//Blazor Server client
builder.Services.AddDragonFlyClient()
.AddIdentity()
.AddApiKeys()
.Init(x =>
{
x.Field().Add<HtmlField>().WithTinyMceView();
});

var app = builder.Build();

Expand Down Expand Up @@ -156,22 +168,18 @@
});
}

IHostEnvironment env = app.Services.GetRequiredService<IHostEnvironment>();

if (env.IsDevelopment())
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseWebAssemblyDebugging();
}

app.UseForwardedHeaders();
app.UseHttpsRedirection();
app.UseDragonFly(x => x
.MapImageWizard()
.MapApiKey()
.MapIdentity()
.MapRestApi());
app.UseDragonFlyManager();
app.UseStaticFiles();
app.UseAntiforgery();
app.UseDragonFly();
//app.UseDragonFlyManager();
app.UseDragonFlyManager<App>();
app.UseSwagger();
app.UseSwaggerUI();

Expand Down
3 changes: 2 additions & 1 deletion src/DragonFly.App.Server/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
},
"MongoDB": {
"Hostname": "localhost",
"Database": "DragonFly_App"
"Database": "DragonFly_App",
"Port": 27019
},
"ImageWizard": {
"Key": "DEMO+KEY+++PLEASE+CHANGE+THIS+KEY+++PLEASE+CHANGE+THIS+KEY+++PLEASE+CHANGE+THIS+KEY+++=="
Expand Down
16 changes: 16 additions & 0 deletions src/DragonFly.App.WebAssembly.Client/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly" AdditionalAssemblies="RazorRoutingManager.Default.Items">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
<Login />
</NotAuthorized>
</AuthorizeRouteView>
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.4" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 433acf3

Please sign in to comment.