Skip to content

Commit

Permalink
Fix CORS configuration for S3 routes
Browse files Browse the repository at this point in the history
Same as bbe6ac6, but for S3 routes.
  • Loading branch information
NSteinhoff committed Sep 12, 2023
1 parent cbf28a9 commit 7e86a6e
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/cdk/add-s3-resource.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {S3Route} from '../read-stack-config.js';
import type {aws_iam, aws_s3} from 'aws-cdk-lib';

import {addCorsPreflight} from './add-cors-preflight.js';
import {aws_apigateway} from 'aws-cdk-lib';
import {join} from 'path';

Expand Down Expand Up @@ -29,11 +30,6 @@ export function addS3Resource(
options: getS3IntegrationOptions(route, bucketReadRole),
});

const corsOptions: aws_apigateway.CorsOptions = {
allowOrigins: aws_apigateway.Cors.ALL_ORIGINS,
allowCredentials: authenticationEnabled,
};

const methodOptions = getS3MethodOptions(route, requestAuthorizer);

if (type === `file`) {
Expand All @@ -42,7 +38,7 @@ export function addS3Resource(
);

if (corsEnabled) {
resource.addCorsPreflight(corsOptions);
addCorsPreflight(resource, {authenticationEnabled});
}

resource.addMethod(`GET`, integration, methodOptions);
Expand All @@ -54,7 +50,7 @@ export function addS3Resource(
);

if (corsEnabled) {
proxyResource.addCorsPreflight(corsOptions);
addCorsPreflight(proxyResource, {authenticationEnabled});
}

proxyResource.addMethod(`GET`, integration, methodOptions);
Expand Down

0 comments on commit 7e86a6e

Please sign in to comment.