Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
configure to use yarp instead
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm360 committed Oct 4, 2024
1 parent 76a9a14 commit 0ea1c65
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 101 deletions.
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# To learn more about .editorconfig see https://aka.ms/editorconfigdocs
# Remove the line below if you want to inherit .editorconfig settings from higher directories
root = true

#### Define style ####

# All files
[*]
indent_style = space

# C# Project, JS and CSS files
[*.{csproj,js,ts,css,scss}]
indent_size = 2

#### Suppress warnings ####

# C# files
[*.cs]

# CA2007: Consider calling ConfigureAwait on the awaited task
dotnet_diagnostic.CA2007.severity = none # Not needed with .Net Core. More info https://devblogs.microsoft.com/dotnet/configureawait-faq/
1 change: 1 addition & 0 deletions BeeTurbo.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
Dockerfile = Dockerfile
nuget.config = nuget.config
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeeTurbo", "src\BeeTurbo\BeeTurbo.csproj", "{41265068-0289-4718-A0C0-7BE6D0E7EC34}"
Expand Down
1 change: 1 addition & 0 deletions src/BeeTurbo/BeeTurbo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Yarp.ReverseProxy" Version="2.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
28 changes: 0 additions & 28 deletions src/BeeTurbo/Controllers/ChunksController.cs

This file was deleted.

30 changes: 22 additions & 8 deletions src/BeeTurbo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@
// You should have received a copy of the GNU Affero General Public License along with BeeTurbo.
// If not, see <https://www.gnu.org/licenses/>.

using Etherna.BeeTurbo.Services;
using Etherna.BeeTurbo.Tools;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using System.Diagnostics.CodeAnalysis;

namespace Etherna.BeeTurbo
{
public static class Program
{
public const string LocalBeeNodeAddress = "http://localhost:8033/";

static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
Expand All @@ -39,22 +42,33 @@ private static void ConfigureServices(WebApplicationBuilder builder)
{
var services = builder.Services;

services.AddControllers();

// Scoped services.
services.AddScoped<IChunksControllerService, ChunksControllerService>();
services.AddHttpForwarder();

// Singleton services.
services.AddSingleton<IChunkStreamTurboServer, ChunkStreamTurboServer>();
}

[SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope")]
private static void ConfigureApplication(WebApplication app)
{
app.UseHttpsRedirection();

app.UseRouting();
app.MapControllers();
app.UseWebSockets();

// Configure endpoint mapping
app.Map("/chunks/stream-turbo", async (HttpContext httpContext, IChunkStreamTurboServer chunkStreamTurboServer) =>
{
if (httpContext.WebSockets.IsWebSocketRequest)
{
var webSocket = await httpContext.WebSockets.AcceptWebSocketAsync();
await chunkStreamTurboServer.HandleWebSocketConnection(webSocket);
}
else
{
httpContext.Response.StatusCode = 400;
await httpContext.Response.WriteAsync("Expected a WebSocket request");
}
});
app.MapForwarder("/{**catch-all}", LocalBeeNodeAddress);
}
}
}
41 changes: 0 additions & 41 deletions src/BeeTurbo/Services/ChunksControllerService.cs

This file was deleted.

24 changes: 0 additions & 24 deletions src/BeeTurbo/Services/IChunksControllerService.cs

This file was deleted.

0 comments on commit 0ea1c65

Please sign in to comment.