import * as pulumi from "@pulumi/pulumi"; import * as aws from "@pulumi/aws"; import * as fg from "fast-glob"; import * as fs from "fs/promises"; import mime from "mime"; import * as common from "./common"; const tags = common.tags; const prefix = `${common.prefix}-frontend`; // ---- bucket ---- export const bucket = new aws.s3.Bucket(`${prefix}-bucket`, {tags}); const bucketOai = new aws.cloudfront.OriginAccessIdentity(`${prefix}-oai`); // ---- cloudfront ---- export const cloudfront = new aws.cloudfront.Distribution(`${prefix}-cloudfront`, { tags, origins: [{ domainName: bucket.bucketRegionalDomainName, originId: bucket.arn, s3OriginConfig: { originAccessIdentity: bucketOai.cloudfrontAccessIdentityPath, }, }], enabled: true, defaultRootObject: "index.html", defaultCacheBehavior: { targetOriginId: bucket.arn, viewerProtocolPolicy: "redirect-to-https", allowedMethods: ["GET", "HEAD", "OPTIONS"], cachedMethods: ["GET", "HEAD", "OPTIONS"], forwardedValues: { queryString: false, cookies: { forward: "none" }, }, }, customErrorResponses: [ { errorCode: 403, responseCode: 200, responsePagePath: "/index.html", }, { errorCode: 404, responseCode: 200, responsePagePath: "/index.html", }, ], priceClass: "PriceClass_100", restrictions: { geoRestriction: { restrictionType: "none", }, }, viewerCertificate: { cloudfrontDefaultCertificate: true, }, });