# Resolving Cors Issues

**URL:** <https://forum.serverless.com/t/resolving-cors-issues/523>\
**Category:** Serverless Framework\
**Tags:** aws\
**Created:** [October 13, 2016, 1:18pm UTC](https://forum.serverless.com/t/resolving-cors-issues/523 "2016-10-13T13:18:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![calben](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/calben/32/205_2.png) [@calben](https://forum.serverless.com/u/calben)\
**Post date:** [October 13, 2016, 1:18pm UTC](https://forum.serverless.com/t/resolving-cors-issues/523/1 "2016-10-13T13:18:39Z")

</div>

Hullo!

I’m trying to get on board with the new Serverless 1.0, and I’m having a bit of an issue with CORS.  
I suspect there’s a tiny thing that I’ve missed in my setup.

To test, I’ve made a function called echo that returns the context and event data for a GET request.  
My function is the following:

```auto
module.exports.echo = (event, context, cb) => {
  context.succeed({
      statusCode: 200,
      headers: {
        "Access-Control-Allow-Origin": "*"
      }
    });
  cb(null, {context, event});
};

```

My yaml file includes the following:

```auto
  echo:
    handler: handler.echo
    events:
      - http:
          path: echo
          method: get
          integration: lambda
          cors:
            origins:
              - '*'

```

When access by URL I am returned the expected echo.  
When I to get the resource by ajax, there is a CORS error:

```auto
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at 
https://??????.execute-api.us-east-1.amazonaws.com/dev/echo?{%22userId%22:%22dummyID%22}&_=??????. 
(Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

```

What should I do to fix this?

---

<div class="post-metadata">

**Author:** ![flomotlik](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/flomotlik/32/3_2.png) [@flomotlik](https://forum.serverless.com/u/flomotlik)\
**Post date:** [October 13, 2016, 3:03pm UTC](https://forum.serverless.com/t/resolving-cors-issues/523/2 "2016-10-13T15:03:04Z")

</div>

Can you try removing the succeed call and only calling the callback with the statuscode/headers hash.

The context.\* methods are outdated for newer versions of Node: [http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html](http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html)

If you want to return context and event in the body you can do (please check for typos):

```auto
module.exports.echo = (event, context, cb) => {
  cb({
      statusCode: 200,
      headers: {
        "Access-Control-Allow-Origin": "*"
      },
      body: JSON.stringify({context, event})
    });
};

```

If that doesn’t work please post the details of the OPTIONS and Get request so we can look in more detail.

---

<div class="post-metadata">

**Author:** ![calben](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/calben/32/205_2.png) [@calben](https://forum.serverless.com/u/calben)\
**Post date:** [October 13, 2016, 5:50pm UTC](https://forum.serverless.com/t/resolving-cors-issues/523/3 "2016-10-13T17:50:26Z")

</div>

Hey @flomotlik thanks for the reply!  
Things are now working 🙂
