Friday 21 April 2017

Angular SPA inconsistent with ANY access-control-allow-methods from API Gateway

We're currently using a Serverless deployment model for our API, with a NodeJS express code base. All was well until we ran into a hard limit for the CloudFormation stacks created by serverless which have a created resource limit of 200.

Trying to work around this while the Serverless team is working on nested stack integration was to replace GET,PUT,POST,DELETE for a single route with ANY which saved us roughly 75% in CloudFormation resources.

API Gateway seemed to take it well, the integration response for the OPTIONS route returned Access-Control-Allow-Methods: 'OPTIONS,ANY'.

Testing this with postman worked like a charm, being able to use all previously mentioned methods without a hitch.

Exercising this from our Angular front-end doesn't seem to work though.

XMLHttpRequest cannot load <api_gateway_resource_url>. Method PUT is not allowed by Access-Control-Allow-Methods in preflight response.

In Angular's eyes, POST, PUT, DELETE, ... don't match up to ANY whereas for postman it does.

Any input why this might be occurring will be greatly appreciated.



via Tom Nijs

No comments:

Post a Comment