Skip to content

Instantly share code, notes, and snippets.

View berkslv's full-sized avatar

Berk Selvi berkslv

View GitHub Profile
@berkslv
berkslv / Startup.cs
Created October 20, 2020 13:18
Startup.cs ConfigureServices for CORS
services.AddCors(options =>
{
options.AddPolicy("ClientPermission", policy =>
{
policy.AllowAnyHeader()
.AllowAnyMethod()
.WithOrigins("http://localhost:3000")
.AllowCredentials();
});
});
@berkslv
berkslv / Startup.cs
Created October 20, 2020 13:15
Startup Configure for mapping
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHub<ChatHub>("/hubs/chat");
});
@berkslv
berkslv / ChatMessage.cs
Created October 20, 2020 13:11
Model for ChatHub.cs
public class ChatMessage
{
public string User { get; set; }
public string Message { get; set; }
}
@berkslv
berkslv / ChatHub.cs
Last active October 20, 2020 13:07
ChatHub, only SendAll
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);
}