Skip to content

Custom Header support #17

Description

@AnalogJ

I'm trying to send a custom header to my Serverless endpoint using AngularJS and JQuery, and whenever I do I get a 403 error during the OPTIONS preflight check.

My s-function.json has:

"requestTemplates": "$${apiRequestTemplate}",
..
"custom": {
    "cors": {
      "allowOrigin": "*",
      "allowHeaders": ["Content-Type", "X-Amz-Date", "X-Custom-Auth", "X-Api-Key"]
    }
  }

My s-templates.json file has:

"apiRequestTemplate": {
    "application/json": {
      "auth": "$input.params('X-Custom-Auth')"
    }
  }

I've tested it with a simple JQuery request:

$.ajax({
    url: "https://***.execute-api.us-east-1.amazonaws.com/dev/test",
    type: 'GET',
    dataType: 'json',
    beforeSend: function(xhr) {
        xhr.setRequestHeader('X-Custom-Auth', 'MY_AUTH');
    }
})
.done(function(data) {
    console.log('JQUERY',data)
})
.fail(function(data) {
    console.log('JQUERYFAIL',data)
});
})

If I comment out the beforeSend block, the request completes successfully.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions