Skip to content
This repository was archived by the owner on Oct 21, 2024. It is now read-only.

Commit 099263d

Browse files
committed
ssr-site: do not deploy CDN in dev mode
1 parent 26519ba commit 099263d

File tree

10 files changed

+168
-342
lines changed

10 files changed

+168
-342
lines changed

pkg/platform/src/components/aws/astro.ts

+23-57
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
Plan,
88
SsrSiteArgs,
99
createBucket,
10+
createDevServer,
1011
createServersAndDistribution,
1112
prepare,
1213
useCloudFrontFunctionHostHeaderInjection,
@@ -319,9 +320,9 @@ const BUILD_META_FILE_NAME: BuildMetaFileName = "sst.buildMeta.json";
319320
* ```
320321
*/
321322
export class Astro extends Component implements Link.Linkable {
322-
private cdn: Output<Cdn>;
323-
private assets: Bucket;
324-
private server: Output<Function>;
323+
private cdn?: Output<Cdn>;
324+
private assets?: Bucket;
325+
private server?: Output<Function>;
325326

326327
constructor(
327328
name: string,
@@ -331,10 +332,22 @@ export class Astro extends Component implements Link.Linkable {
331332
super(__pulumiType, name, args, opts);
332333

333334
const parent = this;
334-
const { sitePath, partition, region } = prepare(args, opts);
335+
const { sitePath, partition } = prepare(args, opts);
336+
337+
if ($dev) {
338+
this.registerOutputs({
339+
_metadata: {
340+
mode: "placeholder",
341+
path: sitePath,
342+
server: createDevServer(parent, name, args).arn,
343+
},
344+
});
345+
return;
346+
}
347+
335348
const { access, bucket } = createBucket(parent, name, partition, args);
336349
const outputPath = buildApp(name, args, sitePath);
337-
const { buildMeta } = loadBuildOutput();
350+
const buildMeta = loadBuildMetadata();
338351
const plan = buildPlan();
339352
const { distribution, ssrFunctions, edgeFunctions } =
340353
createServersAndDistribution(
@@ -352,37 +365,18 @@ export class Astro extends Component implements Link.Linkable {
352365
this.cdn = distribution;
353366
this.server = serverFunction;
354367
this.registerOutputs({
355-
_hint: $dev
356-
? undefined
357-
: all([this.cdn.domainUrl, this.cdn.url]).apply(
358-
([domainUrl, url]) => domainUrl ?? url,
359-
),
368+
_hint: all([this.cdn.domainUrl, this.cdn.url]).apply(
369+
([domainUrl, url]) => domainUrl ?? url,
370+
),
360371
_metadata: {
361-
mode: $dev ? "placeholder" : "deployed",
372+
mode: "deployed",
362373
path: sitePath,
363374
url: distribution.apply((d) => d.domainUrl ?? d.url),
364375
edge: plan.edge,
365376
server: serverFunction.arn,
366377
},
367378
});
368379

369-
function loadBuildOutput() {
370-
const cache = new Cache(
371-
`${name}BuildOutput`,
372-
{
373-
data: $dev ? loadBuildMetadataPlaceholder() : loadBuildMetadata(),
374-
},
375-
{
376-
parent,
377-
ignoreChanges: $dev ? ["*"] : undefined,
378-
},
379-
);
380-
381-
return {
382-
buildMeta: cache.data as ReturnType<typeof loadBuildMetadata>,
383-
};
384-
}
385-
386380
function loadBuildMetadata() {
387381
return outputPath.apply((outputPath) => {
388382
const filePath = path.join(outputPath, "dist", BUILD_META_FILE_NAME);
@@ -397,34 +391,6 @@ export class Astro extends Component implements Link.Linkable {
397391
});
398392
}
399393

400-
function loadBuildMetadataPlaceholder() {
401-
return {
402-
deploymentStrategy: "regional",
403-
responseMode: "buffer",
404-
outputMode: "server",
405-
pageResolution: "directory",
406-
trailingSlash: "ignore",
407-
serverBuildOutputFile: "dist/server/entry.mjs",
408-
clientBuildOutputDir: "dist/client",
409-
clientBuildVersionedSubDir: "_astro",
410-
routes: [
411-
{
412-
route: "/_image",
413-
type: "endpoint",
414-
pattern: "/^\\/_image$/",
415-
prerender: false,
416-
},
417-
{
418-
route: "/",
419-
type: "page",
420-
pattern: "/^\\/$/",
421-
prerender: false,
422-
},
423-
],
424-
serverRoutes: [],
425-
};
426-
}
427-
428394
function buildPlan() {
429395
return all([outputPath, buildMeta]).apply(([outputPath, buildMeta]) => {
430396
const isStatic = buildMeta.outputMode === "static";
@@ -603,7 +569,7 @@ export class Astro extends Component implements Link.Linkable {
603569
* Otherwise, it's the autogenerated CloudFront URL.
604570
*/
605571
public get url() {
606-
return all([this.cdn.domainUrl, this.cdn.url]).apply(
572+
return all([this.cdn?.domainUrl, this.cdn?.url]).apply(
607573
([domainUrl, url]) => domainUrl ?? url,
608574
);
609575
}

pkg/platform/src/components/aws/function.ts

+1-24
Original file line numberDiff line numberDiff line change
@@ -781,10 +781,6 @@ export interface FunctionArgs {
781781
*/
782782
logGroup?: Transform<cloudwatch.LogGroupArgs>;
783783
};
784-
/**
785-
* @internal
786-
*/
787-
_ignoreCodeChanges?: boolean;
788784
/**
789785
* @internal
790786
*/
@@ -1116,17 +1112,6 @@ export class Function extends Component implements Link.Linkable, AWSLinkable {
11161112

11171113
function buildHandler() {
11181114
return dev.apply((dev) => {
1119-
if (args._ignoreCodeChanges) {
1120-
return {
1121-
bundle: path.join(
1122-
$cli.paths.platform,
1123-
"functions",
1124-
"empty-function",
1125-
),
1126-
handler: "index.handler",
1127-
};
1128-
}
1129-
11301115
if (dev) {
11311116
return {
11321117
handler: "bootstrap",
@@ -1398,9 +1383,6 @@ export class Function extends Component implements Link.Linkable, AWSLinkable {
13981383
},
13991384
{
14001385
parent,
1401-
ignoreChanges: args._ignoreCodeChanges
1402-
? ["key", "source"]
1403-
: undefined,
14041386
retainOnDelete: true,
14051387
},
14061388
);
@@ -1456,12 +1438,7 @@ export class Function extends Component implements Link.Linkable, AWSLinkable {
14561438
transformed.architectures = all([transformed.architectures, dev]).apply(
14571439
([architectures, dev]) => (dev ? ["x86_64"] : architectures!),
14581440
);
1459-
return new lambda.Function(`${name}Function`, transformed, {
1460-
parent,
1461-
ignoreChanges: args._ignoreCodeChanges
1462-
? ["code", "handler"]
1463-
: undefined,
1464-
});
1441+
return new lambda.Function(`${name}Function`, transformed, { parent });
14651442
}
14661443

14671444
function createUrl() {

0 commit comments

Comments
 (0)