我已經將API網關設置爲指向lambda函數,設置爲aws_proxy
。我可以GET,POST,刪除就好,但我想添加一個PUT,我得到Method PUT is not allowed by Access-Control-Allow-Methods in preflight response
。方法PUT不允許來自AWS API網關的預檢響應中的訪問控制允許方法
XMLHttpRequest無法加載https://api.small.pictures/picture/07e78691-20f9-4a20-8be5-458eaeb73a63。預檢響應中的訪問控制 - 允許 - 方法不允許方法PUT。
我想我的CORS設置正確。這是路線的招搖者。
'/picture/{picId}':
options:
summary: CORS support
description: |
Enable CORS by returning correct headers
consumes:
- application/json
produces:
- application/json
tags:
- CORS
x-amazon-apigateway-integration:
type: mock
requestTemplates:
application/json: |
{
"statusCode" : 200
}
responses:
"default":
statusCode: "200"
responseParameters:
method.response.header.Access-Control-Allow-Headers : "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'"
method.response.header.Access-Control-Allow-Methods : "'*'"
method.response.header.Access-Control-Allow-Origin : "'*'"
responseTemplates:
application/json: |
{}
parameters:
- name: picId
in: path
required: true
type: string
responses:
200:
description: Default response for CORS method
headers:
Access-Control-Allow-Headers:
type: "string"
Access-Control-Allow-Methods:
type: "string"
Access-Control-Allow-Origin:
type: "string"
x-amazon-apigateway-any-method:
produces:
- "application/json"
responses:
200:
description: "200 response"
schema:
$ref: "#/definitions/Empty"
x-swagger-router-controller: main
x-lambda-function: ../../swiki/build/picture
x-amazon-apigateway-integration:
type: aws_proxy
httpMethod: POST
uri: arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/@@LambdaFunctionPicture/invocations
credentials: @@APIGatewayExecutionRole
正如你可以看到我有Access-Control-Allow-Headers
,Access-Control-Allow-Methods
和Access-Control-Allow-Origin
配置。
爲什麼我無法發出PUT請求?