changed made to make js client work

This commit is contained in:
arhamGIT committed 2023-02-07 10:51:29 -05:00
1 parent 0349ff95bf
commit 86c824e28d
3 files changed
+48 -2

No files matched your search

@@ -3,7 +3,8 @@ using System.Text;
using System.Collections.Concurrent;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace bts.websocket_core {
public enum MessageType {
@@ -430,9 +431,27 @@ namespace bts.websocket_core {
_server_params = server_params;
var builder = WebApplication.CreateBuilder();
builder.WebHost.UseUrls(_server_params.Uri);
var MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
builder.Services.AddLogging(builder => {
builder.AddFilter("Microsoft", Microsoft.Extensions.Logging.LogLevel.Warning)
.AddFilter("System", Microsoft.Extensions.Logging.LogLevel.Warning)
.AddFilter("NToastNotify", Microsoft.Extensions.Logging.LogLevel.Warning)
.AddConsole();
});
builder.Services.AddCors(options => {
options.AddPolicy(MyAllowSpecificOrigins,
policy => policy
.WithOrigins("http://localhost:3000")
.AllowAnyHeader()
.AllowAnyMethod());
});
app = builder.Build();
app.UseWebSockets(_server_params.get_ws_options());
app.Use(async (context, next) => {
context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
context.Response.Headers.Add("Access-Control-Allow-Headers", "*");
await next();
});
app.Map(_server_params.Default_end_point, async context => {
if (context.WebSockets.IsWebSocketRequest) {
using (var ws = await context.WebSockets.AcceptWebSocketAsync()) {
@@ -6,6 +6,13 @@ namespace bts.websocket_core {
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System.Collections.Concurrent;
using bts.api.core;
using bts.api.orderman;
using bts.api.admin;
using bts.co2;
using Spark.Api.Reactive;
using Spark.Api.Orders;
using Spark.Api.Admin;
/// <summary>
@@ -95,6 +102,14 @@ namespace bts.websocket_core {
return new ClientState();
}
}
// ServiceContext? service_ctx;
// ServiceContext Service_Ctx{
// get => Log.notnull<ServiceContext>(service_ctx);
// set {
// Log.isnull(service_ctx);
// service_ctx = value;
// }
// }
MarketDataClient? mdClient;
MarketDataClient MdClient {
@@ -143,6 +158,17 @@ namespace bts.websocket_core {
Gateway = gtwy;
clients = new ClientsStore();
// broadcast = new Thread(() => BroadcastToClients());
// var service_ctx = new ServiceContext();
// var order_service = service_ctx.locate<OrderService>();
// var admin_service = service_ctx.locate<AdminService>();
// var admin_client = new AdminClient(admin_service, UserTuple.admin);
// var md_relay = service_ctx.locate<MarketDataRelay>();
// var md_source = new MDSource(TimeSpan.FromSeconds(0.1));
// var sec_resolver = new SecurityResolver(md_relay, md_source.subscribe_securities());
// var orders_client = new OrdersClient(
// order_service, admin_client, sec_resolver, TimeSpan.FromSeconds(0.1));
TimeSpan md_throttle = new TimeSpan(10000);
MD_Source = new MDSource(md_throttle);
MdClient = new(MD_Source);
@@ -15,6 +15,7 @@
<PackageReference Include="System.Net.WebSockets" Version="4.3.0"/>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.2.0" />
<ProjectReference Include="../spark_core/spark_core.csproj" />
<ProjectReference Include="../spark_api/spark_api.csproj" />
</ItemGroup>