UNPKG

@studion/infra-code-blocks

Version:
53 lines (52 loc) 2.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StaticSite = void 0; const pulumi = require("@pulumi/pulumi"); const cache_rule_ttl_1 = require("./cache-rule-ttl"); const s3_assets_1 = require("./s3-assets"); const cloudfront_1 = require("../cloudfront"); class StaticSite extends pulumi.ComponentResource { name; s3Assets; cf; constructor(name, args, opts = {}) { super('studion:static-site:StaticSite', name, {}, { ...opts, aliases: [...(opts.aliases || []), { type: 'studion:StaticSite' }], }); const { domain, hostedZoneId, certificate, bucketPrefix, indexDocument, errorDocument, cacheRules, tags, } = args; if (!domain && !certificate) { throw new Error('Provide either domain or certificate, or both'); } this.name = name; this.s3Assets = new s3_assets_1.S3Assets(`${this.name}-s3-assets`, { bucketPrefix, indexDocument, errorDocument, tags }, { parent: this }); this.cf = new cloudfront_1.CloudFront(`${this.name}-cf`, { behaviors: this.getCloudFrontBehaviors(cacheRules), domain, certificate, hostedZoneId, tags, }, { parent: this }); this.registerOutputs(); } getCloudFrontBehaviors(cacheRules) { if (!cacheRules) { return [ { type: cloudfront_1.CloudFront.BehaviorType.S3, pathPattern: '*', bucket: this.s3Assets.bucket, websiteConfig: this.s3Assets.websiteConfig, }, ]; } return cacheRules.map(rule => ({ type: cloudfront_1.CloudFront.BehaviorType.S3, pathPattern: rule.pathPattern, bucket: this.s3Assets.bucket, websiteConfig: this.s3Assets.websiteConfig, cacheTtl: (0, cache_rule_ttl_1.parseCacheRuleTtl)(rule.ttl), })); } } exports.StaticSite = StaticSite;