-
-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CORS error trying to consume __admin/mappings #711
Comments
Hello @devmariodiaz, CORS support is not enabled by default, you can enable it yourself when configuring WireMock Server, like: /* https://stackoverflow.com/questions/31942037/how-to-enable-cors-in-asp-net-core */
/* Enable Cors */
settings.AdditionalServiceRegistration = services =>
{
services.AddCors(corsOptions =>
corsOptions.AddPolicy("MyPolicy",
corsPolicyBuilder =>
{
corsPolicyBuilder
.AllowAnyHeader()
.AllowAnyMethod()
.AllowAnyOrigin();
}));
settings.Logger.Debug("Enable Cors");
};
/* Use Cors */
settings.PreWireMockMiddlewareInit = app =>
{
var appBuilder = (IApplicationBuilder)app;
appBuilder.UseCors();
settings.Logger.Debug("Use Cors");
};
_server = WireMockServer.Start(settings); |
I forgot some code. You need to use the same policy-name: /* https://stackoverflow.com/questions/31942037/how-to-enable-cors-in-asp-net-core */
/* Enable Cors */
var policyName = "MyPolicy";
settings.AdditionalServiceRegistration = services =>
{
services.AddCors(corsOptions =>
corsOptions.AddPolicy(policyName, // ◀️ MyPolicy
corsPolicyBuilder =>
{
corsPolicyBuilder
.AllowAnyHeader()
.AllowAnyMethod()
.AllowAnyOrigin();
}));
settings.Logger.Debug("Enable Cors");
};
/* Use Cors */
settings.PreWireMockMiddlewareInit = app =>
{
var appBuilder = (IApplicationBuilder)app;
appBuilder.UseCors(policyName); // ◀️ MyPolicy
settings.Logger.Debug("Use Cors");
}; This works for me: --> |
Thanks a lot for your help, Stef, Now is working fine for me. |
@devmariodiaz Can you try preview (1.4.31-ci-15770) ? var settings = new WireMockServerSettings
{
CorsPolicyOptions = CorsPolicyOptions.AllowAll
}; |
Thanks a lot Stef, I will test this preview ASAP, I believe this is a great decision. |
@devmariodiaz |
Hello Stef,
Happy new year and hoping that you are doing well.
I'm trying to consume __admin/mappings to create new mappings using the method/verb POST and an application developed on React, but I'm getting an error when I send any request. CORS error.
Any clue what I can do to resolve that?
The text was updated successfully, but these errors were encountered: