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
services.AddCors(options => | |
{ | |
options.AddPolicy("ClientPermission", policy => | |
{ | |
policy.AllowAnyHeader() | |
.AllowAnyMethod() | |
.WithOrigins("http://localhost:3000") | |
.AllowCredentials(); | |
}); | |
}); |
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
app.UseEndpoints(endpoints => | |
{ | |
endpoints.MapControllers(); | |
endpoints.MapHub<ChatHub>("/hubs/chat"); | |
}); |
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
public class ChatMessage | |
{ | |
public string User { get; set; } | |
public string Message { 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
using Microsoft.AspNetCore.SignalR; | |
using WebAPI.Helpers.Models; | |
public class ChatHub : Hub | |
{ | |
[HubMethodName("SendMessageToAll")] | |
public async Task SendMessage(ChatMessage message) | |
{ | |
await Clients.All.SendAsync("ReceiveMessage", message); | |
} |
NewerOlder