Skip to content

Commit

Permalink
troubleshooting cors issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ardalis committed Mar 4, 2022
1 parent 8f36e0e commit a94d0b1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using ClinicManagement.Core.Aggregates;
using ClinicManagement.Core.Interfaces;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using PluralsightDdd.SharedKernel.Interfaces;
using Swashbuckle.AspNetCore.Annotations;

Expand All @@ -19,14 +20,17 @@ public class Create : BaseAsyncEndpoint
private readonly IRepository<Doctor> _repository;
private readonly IMapper _mapper;
private readonly IMessagePublisher _messagePublisher;
private readonly ILogger<Create> _logger;

public Create(IRepository<Doctor> repository,
IMapper mapper,
IMessagePublisher messagePublisher)
IMessagePublisher messagePublisher,
ILogger<Create> logger)
{
_repository = repository;
_mapper = mapper;
_messagePublisher = messagePublisher;
_logger = logger;
}

[HttpPost("api/doctors")]
Expand All @@ -50,6 +54,8 @@ public override async Task<ActionResult<CreateDoctorResponse>> HandleAsync(Creat
// In the DbContext you could look for entities marked with an interface saying they needed
// to be synchronized via cross-domain events and publish the appropriate message.
var appEvent = new NamedEntityCreatedEvent(_mapper.Map<NamedEntity>(toAdd), "Doctor-Created");

_logger.LogInformation("Sending doctor created event: {0}", appEvent);
_messagePublisher.Publish(appEvent);

return Ok(response);
Expand Down
2 changes: 1 addition & 1 deletion ClinicManagement/src/ClinicManagement.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void ConfigureServices(IServiceCollection services)
options.AddPolicy(name: CORS_POLICY,
builder =>
{
builder.WithOrigins(baseUrlConfig.WebBase.Replace("host.docker.internal", "localhost").TrimEnd('/'));
builder.WithOrigins(baseUrlConfig.WebBase.Replace("host.docker.internal", "localhost").TrimEnd('/'), "localhost:6100", "localhost:6150");
builder.SetIsOriginAllowed(origin => true);
builder.AllowAnyMethod();
builder.AllowAnyHeader();
Expand Down

0 comments on commit a94d0b1

Please sign in to comment.