Skip to content

Commit 0739011

Browse files
authored
added OPTIONS for apigateway CORS handling (#22)
1 parent 26a8c96 commit 0739011

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Some of the features in this sample app require a LocalStack Pro license - make
4040
Start your LocalStack container with the following configuration:
4141

4242
```bash
43-
EXTRA_CORS_ALLOWED_ORIGINS='*' DISABLE_CUSTOM_CORS_APIGATEWAY=1 DISABLE_CUSTOM_CORS_S3=1 localstack start
43+
localstack start
4444
```
4545

4646
If you run into specific CORS issues, disable it using a [browser extension](https://webextension.org/listing/access-control.html).

bin/deploy.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,33 @@ for ENDPOINT_INFO in "${ENDPOINTS[@]}"; do
212212
--type AWS_PROXY \
213213
--integration-http-method POST \
214214
--uri arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:000000000000:function:${FUNCTION_NAME}/invocations >/dev/null
215+
216+
awslocal apigateway put-method \
217+
--rest-api-id $API_ID \
218+
--resource-id $RESOURCE_ID \
219+
--http-method OPTIONS \
220+
--authorization-type "NONE" >/dev/null
221+
222+
awslocal apigateway put-integration \
223+
--rest-api-id $API_ID \
224+
--resource-id $RESOURCE_ID \
225+
--http-method OPTIONS \
226+
--type MOCK \
227+
--request-templates '{ "application/json": "{\"statusCode\": 200}" }' >/dev/null
228+
229+
awslocal apigateway put-method-response \
230+
--rest-api-id $API_ID \
231+
--resource-id $RESOURCE_ID \
232+
--http-method OPTIONS \
233+
--status-code 204 \
234+
--response-parameters "method.response.header.Access-Control-Allow-Headers=true,method.response.header.Access-Control-Allow-Origin=true,method.response.header.Access-Control-Allow-Methods=true" >/dev/null
235+
236+
awslocal apigateway put-integration-response \
237+
--rest-api-id $API_ID \
238+
--resource-id $RESOURCE_ID \
239+
--http-method OPTIONS \
240+
--status-code 204 \
241+
--response-parameters "{\"method.response.header.Access-Control-Allow-Headers\": \"'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,X-Amz-User-Agent'\", \"method.response.header.Access-Control-Allow-Origin\": \"'*'\", \"method.response.header.Access-Control-Allow-Methods\": \"'OPTIONS,$HTTP_METHOD'\"}" >/dev/null
215242
done
216243
log "API endpoints set up successfully."
217244

docker-compose.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ services:
1313
- LOCALSTACK_AUTH_TOKEN=${LOCALSTACK_AUTH_TOKEN:?} # required for Pro
1414
# LocalStack configuration: https://docs.localstack.cloud/references/configuration/
1515
- DEBUG=${DEBUG:-0}
16-
- EXTRA_CORS_ALLOWED_ORIGINS='*'
17-
- DISABLE_CUSTOM_CORS_APIGATEWAY=1
18-
- DISABLE_CUSTOM_CORS_S3=1
1916
# To setup the LocalStack Extensions
2017
- EXTENSION_AUTO_INSTALL=localstack-extension-event-studio, localstack-extension-mailhog
2118
volumes:

0 commit comments

Comments
 (0)