Access-Control-Allow-Origin Multiple Origin Domains?

前端 未结 30 2152
隐瞒了意图╮
隐瞒了意图╮ 2020-11-21 07:08

Is there a way to allow multiple cross-domains using the Access-Control-Allow-Origin header?

I\'m aware of the *, but it is too open. I rea

30条回答
  •  忘掉有多难
    2020-11-21 07:14

    AWS Lambda/API Gateway

    For information on how to configure multiple origins on Serverless AWS Lambda and API Gateway - albeit a rather large solution for something one would feel should be quite straightforward - see here:

    https://stackoverflow.com/a/41708323/1624933


    It is currently not possible to configure multiple origins in API Gateway, see here: https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors-console.html), but the recommendation (in the answer above) is:

    • inspect the Origin header sent by the browser
    • check it against a whitelist of origins
    • if it matches, return the incoming Origin as the Access-Control-Allow-Origin header, else return a placeholder (default origin).

    The simple solution is obviously enabling ALL (*) like so:

    exports.handler = async (event) => {
        const response = {
            statusCode: 200,
            headers: {
                "Access-Control-Allow-Origin": "*",
                "Access-Control-Allow-Credentials" : true // Required for cookies, authorization headers with HTTPS
            },
            body: JSON.stringify([{
    

    But it might be better to do this on the API Gateway side (see 2nd link above).

提交回复
热议问题