forked from planetarium/libplanet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add a feature that allows you to optionally set whether to star…
…t or not for all services.
- Loading branch information
Showing
23 changed files
with
423 additions
and
138 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
sdk/node/Libplanet.Node.Executable/EntryPoints/DefaultEntryPoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using Libplanet.Node.DependencyInjection; | ||
using Libplanet.Node.Options.Schema; | ||
using Microsoft.AspNetCore.Server.Kestrel.Core; | ||
|
||
namespace Libplanet.Node.API.EntryPoints; | ||
|
||
[Singleton<IApplicationEntryPoint>] | ||
[Singleton<IApplicationBuilderEntryPoint>] | ||
internal sealed class DefaultEntryPoint | ||
: IApplicationEntryPoint, IApplicationBuilderEntryPoint | ||
{ | ||
private const string HandlerMessage = """ | ||
Communication with gRPC endpoints must be made through a gRPC client. To learn how to | ||
create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909 | ||
"""; | ||
|
||
public void Run(WebApplicationBuilder builder) | ||
{ | ||
builder.Logging.AddConsole(); | ||
|
||
if (builder.Environment.IsDevelopment()) | ||
{ | ||
builder.WebHost.ConfigureKestrel(options => | ||
{ | ||
// Setup a HTTP/2 endpoint without TLS. | ||
options.ListenLocalhost(5259, o => o.Protocols = | ||
HttpProtocols.Http1AndHttp2); | ||
}); | ||
} | ||
} | ||
|
||
public async Task RunAsync(WebApplication app, CancellationToken cancellationToken) | ||
{ | ||
var serviceProvider = app.Services; | ||
var schema = await OptionsSchemaBuilder.GetSchemaAsync(cancellationToken); | ||
app.MapGet("/", () => HandlerMessage); | ||
app.MapGet("/schema", () => schema); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
sdk/node/Libplanet.Node.Executable/EntryPoints/GrpcServiceEntryPoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using Libplanet.Node.API.Extensions; | ||
using Libplanet.Node.API.Options; | ||
using Libplanet.Node.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Libplanet.Node.API.EntryPoints; | ||
|
||
[Singleton<IApplicationBuilderEntryPoint>] | ||
[Singleton<IApplicationEntryPoint>] | ||
internal sealed class GrpcServiceEntryPoint( | ||
IOptions<GrpcOptions> options, IWebHostEnvironment environment) | ||
: IApplicationBuilderEntryPoint, IApplicationEntryPoint | ||
{ | ||
private readonly GrpcOptions _options = options.Value; | ||
|
||
public Task RunAsync(WebApplication app, CancellationToken cancellationToken) | ||
{ | ||
var serviceProvider = app.Services; | ||
var nodeBuilder = serviceProvider.GetRequiredService<INodeApplicationBuilder>(); | ||
app.MapGrpcServiceFromDomain(nodeBuilder.Scopes); | ||
if (environment.IsDevelopment()) | ||
{ | ||
app.MapGrpcReflectionService().AllowAnonymous(); | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
public void Run(WebApplicationBuilder builder) | ||
{ | ||
if (_options.IsEnabled) | ||
{ | ||
builder.Services.AddGrpc(); | ||
|
||
if (environment.IsDevelopment()) | ||
{ | ||
builder.Services.AddGrpcReflection(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using Libplanet.Node; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.ComponentModel; | ||
using Libplanet.Node.DependencyInjection; | ||
using Libplanet.Node.Options; | ||
|
||
namespace Libplanet.Node.API.Options; | ||
|
||
[Options(Position)] | ||
public sealed class GrpcOptions : OptionsBase<GrpcOptions> | ||
{ | ||
public const string Position = "Grpc"; | ||
|
||
[DefaultValue(true)] | ||
public bool IsEnabled { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,2 @@ | ||
using Libplanet.Node.Extensions; | ||
using Libplanet.Node.Options.Schema; | ||
using Microsoft.AspNetCore.Server.Kestrel.Core; | ||
|
||
SynchronizationContext.SetSynchronizationContext(new()); | ||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.Logging.AddConsole(); | ||
|
||
if (builder.Environment.IsDevelopment()) | ||
{ | ||
builder.WebHost.ConfigureKestrel(options => | ||
{ | ||
// Setup a HTTP/2 endpoint without TLS. | ||
options.ListenLocalhost(5259, o => o.Protocols = | ||
HttpProtocols.Http1AndHttp2); | ||
}); | ||
} | ||
|
||
// Additional configuration is required to successfully run gRPC on macOS. | ||
// For instructions on how to configure Kestrel and gRPC clients on macOS, | ||
// visit https://go.microsoft.com/fwlink/?linkid=2099682 | ||
|
||
// Add services to the container. | ||
builder.Services.AddGrpc(); | ||
builder.Services.AddGrpcReflection(); | ||
var libplanetBuilder = builder.Services.AddLibplanetNode(builder.Configuration) | ||
.WithSeed() | ||
.WithNode(); | ||
|
||
var app = builder.Build(); | ||
var handlerMessage = """ | ||
Communication with gRPC endpoints must be made through a gRPC client. To learn how to | ||
create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909 | ||
"""; | ||
var schema = await OptionsSchemaBuilder.GetSchemaAsync(default); | ||
|
||
// Configure the HTTP request pipeline. | ||
app.MapGrpcServiceFromDomain(libplanetBuilder.Scopes); | ||
app.MapGet("/", () => handlerMessage); | ||
app.MapGet("/schema", () => schema); | ||
|
||
if (builder.Environment.IsDevelopment()) | ||
{ | ||
app.MapGrpcReflectionService().AllowAnonymous(); | ||
} | ||
|
||
await using var app = new NodeApplication(args); | ||
await app.RunAsync(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
sdk/node/Libplanet.Node.Extensions/NodeBuilder/ILibplanetNodeBuilder.cs
This file was deleted.
Oops, something went wrong.
47 changes: 0 additions & 47 deletions
47
sdk/node/Libplanet.Node.Extensions/NodeBuilder/LibplanetNodeBuilder.cs
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
sdk/node/Libplanet.Node/DependencyInjection/IApplicationBuilderEntryPoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
|
||
namespace Libplanet.Node.DependencyInjection; | ||
|
||
public interface IApplicationBuilderEntryPoint | ||
{ | ||
void Run(WebApplicationBuilder builder); | ||
} |
8 changes: 8 additions & 0 deletions
8
sdk/node/Libplanet.Node/DependencyInjection/IApplicationEntryPoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
|
||
namespace Libplanet.Node.DependencyInjection; | ||
|
||
public interface IApplicationEntryPoint | ||
{ | ||
Task RunAsync(WebApplication app, CancellationToken cancellationToken); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.