Response to preflight request doesn't pass access control check

后端 未结 21 2564
别那么骄傲
别那么骄傲 2020-11-22 03:50

I\'m getting this error using ngResource to call a REST API on Amazon Web Services:

XMLHttpRequest cannot load http://server.apiurl.com:8000/s/login

21条回答
  •  猫巷女王i
    2020-11-22 04:17

    For those are using Lambda Integrated Proxy with API Gateway. You need configure your lambda function as if you are submitting your requests to it directly, meaning the function should set up the response headers properly. (If you are using custom lambda functions, this will be handled by the API Gateway.)

    //In your lambda's index.handler():
    exports.handler = (event, context, callback) => {
         //on success:
         callback(null, {
               statusCode: 200,
               headers: {
                    "Access-Control-Allow-Origin" : "*"
               }
         }
    }
    

提交回复
热议问题