From e7a0a468ce71b47d81173e17aee3ea57d3f13456 Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 30 Jul 2024 19:55:00 -0400 Subject: [PATCH 1/2] acp --- client/src/helpers.rs | 1 + server/Program.cs | 8 +++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/client/src/helpers.rs b/client/src/helpers.rs index 3e911e1..34174c0 100644 --- a/client/src/helpers.rs +++ b/client/src/helpers.rs @@ -70,6 +70,7 @@ pub fn create_auth_header(token: &String) -> Headers { let auth = format!("Bearer {}", token); let hdrs = Headers::new(); hdrs.append("Authorization", &auth); + hdrs.append("Content-Type", "multipart/form-data"); hdrs } diff --git a/server/Program.cs b/server/Program.cs index 66ca4c2..3086a3a 100644 --- a/server/Program.cs +++ b/server/Program.cs @@ -22,10 +22,9 @@ public static void Main(string[] args) // --------------------- CORS POLICY ------------------------------ builder.Services.AddCors(options => { - var allowedOrigins = new[] { "https://thedevblog.net", "https://www.thedevblog.net" }; options.AddPolicy("AllowSpecificOrigin", builder => { - builder.WithOrigins(allowedOrigins) + builder.WithOrigins("https://thedevblog.net", "https://www.thedevblog.net") .AllowAnyHeader() .AllowAnyMethod(); }); @@ -106,6 +105,8 @@ public static void Main(string[] args) var app = builder.Build(); + // ------------------- MIDDLEWARE ------------------------------- + app.UseCors("AllowSpecificOrigin"); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) @@ -119,9 +120,6 @@ public static void Main(string[] args) app.UseSwaggerUI(); } - // ------------------- MIDDLEWARE ------------------------------- - app.UseCors("AllowSpecificOrigin"); - // ----------------------- ROUTING ------------------------------- app.UseHttpsRedirection(); app.UseRouting(); From 1fb750518be8f5d5e6ddcfa601eaeef99baae42d Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 30 Jul 2024 19:58:25 -0400 Subject: [PATCH 2/2] update --- client/src/helpers.rs | 1 - client/src/pages/post_add.rs | 1 + server/Program.cs | 11 +++++------ 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/client/src/helpers.rs b/client/src/helpers.rs index 34174c0..3e911e1 100644 --- a/client/src/helpers.rs +++ b/client/src/helpers.rs @@ -70,7 +70,6 @@ pub fn create_auth_header(token: &String) -> Headers { let auth = format!("Bearer {}", token); let hdrs = Headers::new(); hdrs.append("Authorization", &auth); - hdrs.append("Content-Type", "multipart/form-data"); hdrs } diff --git a/client/src/pages/post_add.rs b/client/src/pages/post_add.rs index bcdc8f1..384cc17 100644 --- a/client/src/pages/post_add.rs +++ b/client/src/pages/post_add.rs @@ -59,6 +59,7 @@ pub fn add_post() -> Html { let devblog_status = devblog_status.clone(); let hdrs = helpers::create_auth_header(&token); + hdrs.append("Content-Type", "multipart/form-data"); let form_data = FormData::new().unwrap(); let _ = form_data.append_with_str("description", &description); let _ = form_data.append_with_str("postToDiscord", &discord.to_string()); diff --git a/server/Program.cs b/server/Program.cs index 3086a3a..40ccfd0 100644 --- a/server/Program.cs +++ b/server/Program.cs @@ -22,12 +22,10 @@ public static void Main(string[] args) // --------------------- CORS POLICY ------------------------------ builder.Services.AddCors(options => { - options.AddPolicy("AllowSpecificOrigin", builder => - { - builder.WithOrigins("https://thedevblog.net", "https://www.thedevblog.net") - .AllowAnyHeader() - .AllowAnyMethod(); - }); + var allowedOrigins = builder.Configuration.GetSection("AllowedOrigins").Get(); + options.AddPolicy("AllowSpecificOrigin", b => b.WithOrigins(allowedOrigins) + .AllowAnyHeader() + .AllowAnyMethod()); }); // --------------------- SWAGGER ---------------------------------- @@ -108,6 +106,7 @@ public static void Main(string[] args) // ------------------- MIDDLEWARE ------------------------------- app.UseCors("AllowSpecificOrigin"); + // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) {