diff --git a/README.md b/README.md index a02a452..5a4c339 100644 --- a/README.md +++ b/README.md @@ -84,12 +84,12 @@ features are as follows: export interface AWSAdapterProps { artifactPath?: string // Build output directory (default: build) autoDeploy?: boolean // Should automatically deploy in SvelteKit build step (default: false) + cachePolicy?: string // Cloudfront managed cache policy (default: 'Managed-CachingOptimized') defaultHeaders?: string[] // Default whitelist of headers for the SSR server. (default: ['Accept','Accept-Language','If-None-Match','Host','Origin','Referer','X-Forwarded-Host']) - extraHeaders?: string[] // Additional headers to add to whitelist. (default: []) esbuildOptions?: any // Override or extend default esbuild options for the SSR server. Supports `external` (default `['node:*']`), `format` (default `cjs`), `target` (default `node18`), `banner` (default `{}`). + extraHeaders?: string[] // Additional headers to add to whitelist. (default: []) FQDN?: string // Full qualified domain name of CloudFront deployment (e.g. demo.example.com) memorySize?: number // Memory size of SSR lambda in MB (default: 128) - pulumiPaths: string[] // For internal use only region?: string // Region to deploy resources (default: us-east-2) serverStreaming?: boolean // Use lambda streaming responses for SSR server (default: false) stackName?: string // Pulumi stack name (default: dev) @@ -118,7 +118,7 @@ in the SvelteKit documentation for further details. A script is provided to destroy the infrastructure, with the following signature: -``` +```console adapter-stack-destroy [artifactPath] Destroy the SvelteKit adapter's Pulumi stacks diff --git a/adapter.ts b/adapter.ts index d3b20a4..5df523e 100644 --- a/adapter.ts +++ b/adapter.ts @@ -17,20 +17,22 @@ const __dirname = url.fileURLToPath(new URL('.', import.meta.url)) export interface AWSAdapterProps { artifactPath?: string autoDeploy?: boolean + cachePolicy?: string defaultHeaders?: string[] - extraHeaders?: string[] esbuildOptions?: any + extraHeaders?: string[] FQDN?: string - pulumiPaths?: string[] memorySize?: number + pulumiPaths?: string[] region?: string serverStreaming?: boolean - stackName?: string + stackName: string } export function adapter({ artifactPath = 'build', autoDeploy = false, + cachePolicy = 'Managed-CachingOptimized', defaultHeaders = [ 'Accept', 'Accept-Language', @@ -44,11 +46,10 @@ export function adapter({ esbuildOptions = {}, FQDN, memorySize = 128, - pulumiPaths = [], region = 'us-east-2', serverStreaming = false, stackName = 'dev', -}: AWSAdapterProps = {}) { +}: AWSAdapterProps) { /** @type {import('@sveltejs/kit').Adapter} */ return { name: 'adapter-aws-pulumi', @@ -64,8 +65,6 @@ export function adapter({ const options_directory = await buildOptions(builder, artifactPath) if (autoDeploy) { - let adapterProps: AWSAdapterProps = {} - builder.log.minor('Deploy using Pulumi.') // Setup server stack. @@ -78,6 +77,7 @@ export function adapter({ await serverStack.setAllConfig({ 'aws:region': { value: region }, + cachePolicy: { value: cachePolicy }, projectPath: { value: process.cwd() }, serverPath: { value: server_directory }, optionsPath: { value: options_directory }, @@ -158,8 +158,11 @@ export function adapter({ onOutput: console.info, }) - adapterProps.pulumiPaths = [serverPath, mainPath] - adapterProps.stackName = stackName + const adapterProps: AWSAdapterProps = { + pulumiPaths: [serverPath, mainPath], + stackName: stackName, + } + writeFileSync( join(artifactPath, '.adapterprops.json'), JSON.stringify(adapterProps), diff --git a/stacks/main/index.ts b/stacks/main/index.ts index 7e823e0..764d731 100644 --- a/stacks/main/index.ts +++ b/stacks/main/index.ts @@ -11,13 +11,14 @@ import { } from './resources.js' const pulumiConfig = new pulumi.Config() +const cachePolicy = pulumiConfig.require('cachePolicy') const edgePath = pulumiConfig.require('edgePath') -const staticPath = pulumiConfig.require('staticPath') +const FQDN = pulumiConfig.get('FQDN') +const optionsArn = pulumiConfig.require('optionsArn') const prerenderedPath = pulumiConfig.require('prerenderedPath') const serverArn = pulumiConfig.require('serverArn') -const optionsArn = pulumiConfig.require('optionsArn') -const FQDN = pulumiConfig.get('FQDN') const serverHeadersStr = pulumiConfig.get('serverHeaders') +const staticPath = pulumiConfig.require('staticPath') let serverHeaders: string[] = [] @@ -43,6 +44,7 @@ const distribution = buildCDN( serverHeaders, FQDN, certificateArn, + cachePolicy, ) if (FQDN) { diff --git a/stacks/main/resources.ts b/stacks/main/resources.ts index 570dd9d..701cb25 100644 --- a/stacks/main/resources.ts +++ b/stacks/main/resources.ts @@ -213,6 +213,7 @@ export function buildCDN( serverHeaders: string[], FQDN?: string, certificateArn?: pulumi.Input, + cachePolicy: string = 'Managed-CachingOptimized', ): aws.cloudfront.Distribution { const defaultRequestPolicy = new aws.cloudfront.OriginRequestPolicy( registerName('DefaultRequestPolicy'), @@ -244,7 +245,7 @@ export function buildCDN( ) const optimizedCachePolicy = aws.cloudfront.getCachePolicyOutput({ - name: 'Managed-CachingOptimized', + name: cachePolicy, }) const distribution = new aws.cloudfront.Distribution( diff --git a/tests/stacks.main.resources.test.ts b/tests/stacks.main.resources.test.ts index d671071..80a982b 100644 --- a/tests/stacks.main.resources.test.ts +++ b/tests/stacks.main.resources.test.ts @@ -146,9 +146,7 @@ describe('stacks/main/resources.ts', () => { role: 'mock', }) const bucket = new aws.s3.Bucket('MockBucket') - const routes = ['mock/*', 'another/*'] const serverHeaders = ['mock1', 'mock2'] - const staticHeaders = ['mock3'] const FQDN = 'server.example.com' const certificateArn = 'MockCertificateArn' const bucketId = await promiseOf(bucket.id)