RT server and signalr
This commit is contained in:
9
dotnet/AipsRT/AipsRT.csproj
Normal file
9
dotnet/AipsRT/AipsRT.csproj
Normal file
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
11
dotnet/AipsRT/Hubs/TestHub.cs
Normal file
11
dotnet/AipsRT/Hubs/TestHub.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace AipsRT.Hubs;
|
||||
|
||||
public class TestHub : Hub
|
||||
{
|
||||
public async Task SendText(string text)
|
||||
{
|
||||
await Clients.All.SendAsync("ReceiveText", text);
|
||||
}
|
||||
}
|
||||
31
dotnet/AipsRT/Program.cs
Normal file
31
dotnet/AipsRT/Program.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using AipsRT.Hubs;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Services.AddSignalR();
|
||||
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("frontend",
|
||||
policy =>
|
||||
{
|
||||
policy
|
||||
.WithOrigins("http://localhost:5173")
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod()
|
||||
.AllowCredentials();
|
||||
});
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.MapGet("/test", (IHubContext<TestHub> hubContext) =>
|
||||
{
|
||||
hubContext.Clients.All.SendAsync("ReceiveText", "Ide gas! ");
|
||||
});
|
||||
|
||||
app.UseCors("frontend");
|
||||
app.MapHub<TestHub>("/testhub");
|
||||
|
||||
app.Run();
|
||||
23
dotnet/AipsRT/Properties/launchSettings.json
Normal file
23
dotnet/AipsRT/Properties/launchSettings.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5039",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:7287;http://localhost:5039",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user