jin-qu/jinqu-odata

CORS policy problem

Closed this issue · 3 comments

Access to fetch at 'http://localhost:55106/admin/api/v1/apps/1/categories/1' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

Can you please provide an example how we can allow origin for the request
const service = new ODataService ("http://localhost:55106/admin/api/v1/apps/1/")
const books = await service
.createQuery(Category)
.toArrayAsync()

thanks

Thanks for the feedback!

jinqu-odata uses a request provider in the background (default is fetch). It calls your OData provider (server side).
So, you shouldn't configure jinqu for CORS, but providers.

For fetch you might want to check this out: https://javascript.info/fetch-crossorigin
(btw, fetch should work automatically with correctly configured servers)

For server side (Asp.Net Core OData for example): OData/WebApi#1611

Hope this helps.

Thanks for your prompt response, you save my day.

all i need to do for testing is to allow any origin from the server like below in the service configuration :
services.AddCors(options =>
{
options.AddPolicy(
"AllowAllOrigins",
builder => builder
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod()
);

options.DefaultPolicyName = "AllowAllOrigins";
});

and to use this policy in the app pipline like

app.UseCors("AllowAllOrigins");

thanks again.

Glad it's solved 👍