这个问题通常是由于API Gateway无法正确处理跨域请求而导致的,可以使用以下代码示例来解决问题:
在API Gateway中创建一个OPTIONS方法:
// OPTIONS method for CORS pre-flight request
app.options('/.well-known/openid-configuration', function(req, res) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,PATCH,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
res.send(200);
});
然后在路由中添加以下代码:
// GET /.well-known/openid-configuration
app.get('/.well-known/openid-configuration', function(req, res) {
var options = {
url: 'https://appleid.apple.com/.well-known/openid-configuration',
headers: {
'User-Agent': 'request'
}
};
request(options, function(error, response, body) {
if (!error && response.statusCode == 200) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,PATCH,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
res.send(body);
} else {
console.log(error);
res.send(500, '{"error": "Error"}');
}
});
});
这个代码示例将解决跨域请求和获取Apple的/.well-known/openid-configuration的问题。