export class TodoFrontend extends Construct { constructor(scope: Construct, id: string, props: TodoFrontendProps) { // S3バケットの作成 this.websiteBucket = new s3.Bucket(this, 'TodoWebsiteBucket', { removalPolicy: cdk.RemovalPolicy.DESTROY, autoDeleteObjects: true, enforceSSL: true, }); // CloudFrontディストリビューションの作成 this.distribution = new cloudfront.Distribution(this, 'TodoDistribution', { defaultBehavior: { origin: origins.S3BucketOrigin.withOriginAccessControl(this.websiteBucket), viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS, allowedMethods: cloudfront.AllowedMethods.ALLOW_GET_HEAD, }, additionalBehaviors: { 'todos*': { origin: new origins.RestApiOrigin(props.todoApi), cachePolicy: cloudfront.CachePolicy.CACHING_DISABLED, // キャッシュを無効化 viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS, // HTTPSへリダイレクト allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL, // すべてのHTTPメソッドを許可 }, }, defaultRootObject: 'index.html', }); } } 23