Created
April 27, 2018 03:11
-
-
Save maruware/21370753be383e2a0eec7c5d4958b5b8 to your computer and use it in GitHub Desktop.
Attach cors header on AWS Lambda (nodejs8.10)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = (response) => { | |
const {headers, ...rest} = response | |
return { | |
...rest, | |
headers: { | |
'Access-Control-Allow-Origin': '*', | |
...headers | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cors = require('./cors') | |
module.exports.hello = (event, context, callback) => { | |
const response = { | |
statusCode: 200, | |
body: JSON.stringify({ | |
msg: 'hello, world!' | |
}) | |
} | |
callback(null, cors(response)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment