Skip to content

Commit

Permalink
fix(infra): allow cross origin requests to the static s3 bucket (#1939)
Browse files Browse the repository at this point in the history
  • Loading branch information
blacha authored Oct 27, 2021
1 parent 320a55f commit 68573a0
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions packages/_infra/src/edge/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import cf from '@aws-cdk/aws-cloudfront';
import s3, { Bucket } from '@aws-cdk/aws-s3';
import s3, { Bucket, HttpMethods } from '@aws-cdk/aws-s3';
import cdk from '@aws-cdk/core';
import { getConfig } from '../config.js';
import { Parameters } from '../parameters.js';
Expand All @@ -23,7 +23,15 @@ export class EdgeStack extends cdk.Stack {
super(scope, id, props);

const config = getConfig();
const s3BucketSource = new s3.Bucket(this, 'StaticBucket');
const s3BucketSource = new s3.Bucket(this, 'StaticBucket', {
cors: [
{
allowedOrigins: ['*'],
allowedMethods: [HttpMethods.GET, HttpMethods.HEAD],
allowedHeaders: ['*'],
},
],
});

// Allow cloud front to read the static bucket
const originAccessIdentity = new cf.OriginAccessIdentity(this, 'AccessIdentity', {
Expand All @@ -34,7 +42,16 @@ export class EdgeStack extends cdk.Stack {

const s3Source: cf.SourceConfiguration = {
s3OriginSource: { s3BucketSource, originAccessIdentity },
behaviors: [{ isDefaultBehavior: true }],
behaviors: [
{
isDefaultBehavior: true,
allowedMethods: cf.CloudFrontAllowedMethods.GET_HEAD_OPTIONS,
forwardedValues: {
queryString: true,
headers: ['Access-Control-Allow-Origin'],
},
},
],
};

const tileSource: cf.SourceConfiguration = {
Expand Down

0 comments on commit 68573a0

Please sign in to comment.