From 6c5fe1bc003843da12cd1a4272b2520b6671df80 Mon Sep 17 00:00:00 2001 From: Mohammad Mahdi Date: Thu, 24 Apr 2025 19:07:43 +0330 Subject: [PATCH] Added cors --- Program.cs | 15 +++++++++++++-- Web/ServerStartup.cs | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Program.cs b/Program.cs index 3dc4791..f4f689a 100755 --- a/Program.cs +++ b/Program.cs @@ -2,6 +2,7 @@ using CatsOfMastodonBot.Models; using CatsOfMastodonBot.Services; using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using mstdnCats.Services; @@ -41,12 +42,22 @@ public class MastodonBot { options.ListenAnyIP(5005); // Listen on port 5005 }); + webBuilder.ConfigureServices(services => + { + services.AddCors(options => + { + options.AddDefaultPolicy(options => + { + options.AllowAnyHeader() + .AllowAnyMethod() + .AllowAnyOrigin(); + }); + }); + } ); ServerStartup.Serverstartup(db); webBuilder.UseStartup(); }) .Build(); - - // Setup bot TelegramBotClient bot; diff --git a/Web/ServerStartup.cs b/Web/ServerStartup.cs index 1922e48..a197799 100755 --- a/Web/ServerStartup.cs +++ b/Web/ServerStartup.cs @@ -19,7 +19,7 @@ public class ServerStartup public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseRouting(); - + app.UseCors(); app.UseEndpoints(endpoints => { endpoints.MapGet("/", async context =>