Skip to content

Commit

Permalink
enabling CORs for client site
Browse files Browse the repository at this point in the history
  • Loading branch information
andrenormanlang committed Sep 11, 2024
1 parent 343ab29 commit 54be1b9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions InventoryManagementSystem/Controllers/ProductController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ public async Task<ActionResult<IEnumerable<Product>>> PostProductsInBulk(IEnumer
var category = await _context.Categories.FindAsync(productDto.CategoryId);
var supplier = await _context.Suppliers.FindAsync(productDto.SupplierId);

if (productDto.Description.Length > 10000)
{
return BadRequest("Description cannot exceed 10,000 characters.");
}

if (category == null)
{
return BadRequest(new { message = $"Invalid Category ID: {productDto.CategoryId} for product: {productDto.Name}. Category does not exist." });
Expand Down
4 changes: 2 additions & 2 deletions InventoryManagementSystem/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
options.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles;
});

// Enable CORS
// Enable CORS to allow requests from Blazor client
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowBlazorClient", policy =>
Expand Down Expand Up @@ -88,7 +88,7 @@
app.UseHttpsRedirection();
app.UseStaticFiles();

// Enable CORS
// Enable CORS with the configured policy
app.UseCors("AllowBlazorClient");

app.UseRouting();
Expand Down

0 comments on commit 54be1b9

Please sign in to comment.