moleculerjs / moleculer-web

:earth_africa: Official API Gateway service for Moleculer framework
http://moleculer.services/docs/moleculer-web.html
MIT License
291 stars 119 forks source link

CORS not working #160

Closed yogeshvfs closed 4 years ago

yogeshvfs commented 4 years ago

I've created number of APIs in the following way:

routes: [{ authorization: true, path: '/v1/api/:client', cors: { origin: "*", methods: ["GET", "POST", "OPTIONS", "PUT"], allowedHeaders: [], exposedHeaders: [], credentials: false, maxAge: 3600 } aliases: { "POST /users": "user.createUser", "GET /users": "user.getUsers" } }]

I'm not able to access the APIs with Angular application running at server http://localhost:4200

With an error: Access to fetch at 'http://localhost:8000/v1/api/choclates/users' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

riterrani commented 4 years ago

I have the same problem. I am using the same CORS configuration

icebob commented 4 years ago

The POST request send Content-Type header, which is not allowed in your CORS config. Use allowedHeaders: "*" or allowedHeaders: ["Content-Type"]