Friday, August 24, 2018

CORS error on microservice health check.

I've followed this microservice health check guide to add health checks to an app: Guide

Seems straight forward. However, getting a classic CORS error, but can access it in postman.

Just wondering if anyone has run into a similar issue using health checks. My concern is the endpoint is added in the program (which might be before cors is disabled?).

There is also this line:

When you have configured health checks as described here, once the microservice is running in Docker, you can directly check from a browser if it is healthy. (This does require that you are publishing the container port out of the Docker host, so you can access the container through localhost or through the external Docker host IP.) Figure 10-7 shows a request in a browser and the corresponding response.

I'm not in a Docker yet, so I don't think pertains to me.

Here's a sample of my startup. Even if I turn off CORS, it's still not working.

 namespace Application { public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddPolicy("Cors", builder => builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials()); }); services.AddMvc(); services.AddOptions(); services.Configure<DbContext>(Configuration.GetSection("ConnectionStrings")); services.AddHealthChecks(checks => { checks.AddValueTaskCheck("HTTP Endpoint", () => new ValueTask<IHealthCheckResult>(HealthCheckResult.Healthy("OK"))); }); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseCors("Cors"); app.UseMvc(); } } } 
CORS error on microservice health check. Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team