From cd0dd8d7e113d94b649cbfaf7ba2bba70752923d Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Sun, 12 Apr 2026 13:34:13 +0100 Subject: [PATCH] Added hub to send datetime on front --- BeReadyBackend/Hubs/TimeHub.cs | 15 +++++++++++++++ BeReadyBackend/Program.cs | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 BeReadyBackend/Hubs/TimeHub.cs diff --git a/BeReadyBackend/Hubs/TimeHub.cs b/BeReadyBackend/Hubs/TimeHub.cs new file mode 100644 index 0000000..b082c04 --- /dev/null +++ b/BeReadyBackend/Hubs/TimeHub.cs @@ -0,0 +1,15 @@ +using Microsoft.AspNetCore.SignalR; + +namespace BeReadyBackend.Hubs; + +public class TimeHub : Hub +{ + public async Task SendTime() + { + while (true) + { + await Clients.All.SendAsync("ReceiveTime", DateTime.Now); + await Task.Delay(1000); + } + } +} \ No newline at end of file diff --git a/BeReadyBackend/Program.cs b/BeReadyBackend/Program.cs index 6452252..ccbd9ef 100644 --- a/BeReadyBackend/Program.cs +++ b/BeReadyBackend/Program.cs @@ -25,7 +25,8 @@ builder.Services .WithOrigins("http://localhost:4200") .WithMethods("GET", "POST", "PUT", "DELETE", "PATCH") .AllowAnyHeader() - .WithExposedHeaders(HeaderNames.ContentDisposition); + .WithExposedHeaders(HeaderNames.ContentDisposition) + .AllowCredentials(); }); }) .SwaggerDocument(options => { options.ShortSchemaNames = true; }); @@ -71,6 +72,7 @@ app.UseAuthentication() .UseSwaggerGen(); app.MapHub("/groupHub"); +app.MapHub("/timeHub"); //app.UseHttpsRedirection();