Skip to content

Commit 052bb10

Browse files
committed
addressed review comments
1 parent bab1ebc commit 052bb10

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

packages/@aws-cdk/aws-amplify-alpha/lib/app.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { CfnApp } from 'aws-cdk-lib/aws-amplify';
66
import { BasicAuth } from './basic-auth';
77
import { Branch, BranchOptions } from './branch';
88
import { Domain, DomainOptions } from './domain';
9-
import { renderEnvironmentVariables } from './utils';
9+
import { renderEnvironmentVariables, isServerSideRendered } from './utils';
1010
import { addConstructMetadata, MethodMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
1111
import { propertyInjectable } from 'aws-cdk-lib/core/lib/prop-injectable';
1212

@@ -20,11 +20,6 @@ export interface IApp extends IResource {
2020
* @attribute
2121
*/
2222
readonly appId: string;
23-
24-
/**
25-
* The platform of the app
26-
*/
27-
readonly platform?: Platform;
2823
}
2924

3025
/**
@@ -267,7 +262,7 @@ export class App extends Resource implements IApp, iam.IGrantable {
267262

268263
let computedRole: iam.IRole | undefined;
269264
const appPlatform = props.platform || Platform.WEB;
270-
const isSSR = appPlatform === Platform.WEB_COMPUTE || appPlatform === Platform.WEB_DYNAMIC;
265+
const isSSR = isServerSideRendered(appPlatform);
271266

272267
if (props.computeRole) {
273268
if (!isSSR) {

packages/@aws-cdk/aws-amplify-alpha/lib/branch.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import {
1414
import { Provider } from 'aws-cdk-lib/custom-resources';
1515
import { Construct } from 'constructs';
1616
import { CfnBranch } from 'aws-cdk-lib/aws-amplify';
17-
import { IApp, Platform } from './app';
17+
import { App, IApp, Platform } from './app';
1818
import { BasicAuth } from './basic-auth';
19-
import { renderEnvironmentVariables } from './utils';
19+
import { renderEnvironmentVariables, isServerSideRendered } from './utils';
2020
import { AssetDeploymentIsCompleteFunction, AssetDeploymentOnEventFunction } from '../custom-resource-handlers/dist/aws-amplify-alpha/asset-deployment-provider.generated';
2121
import { addConstructMetadata, MethodMetadata } from 'aws-cdk-lib/core/lib/metadata-resource';
2222
import { propertyInjectable } from 'aws-cdk-lib/core/lib/prop-injectable';
@@ -194,11 +194,13 @@ export class Branch extends Resource implements IBranch {
194194
// Enhanced CDK Analytics Telemetry
195195
addConstructMetadata(this, props);
196196

197-
const platform = props.app.platform;
198-
const isSSR = platform === Platform.WEB_COMPUTE || platform === Platform.WEB_DYNAMIC;
197+
if (props.app instanceof App) {
198+
const platform = props.app.platform;
199+
const isSSR = isServerSideRendered(platform);
199200

200-
if (props.computeRole && !isSSR) {
201-
throw new ValidationError('`computeRole` can only be specified for branches of apps with `Platform.WEB_COMPUTE` or `Platform.WEB_DYNAMIC`.', this);
201+
if (props.computeRole && !isSSR) {
202+
throw new ValidationError('`computeRole` can only be specified for branches of apps with `Platform.WEB_COMPUTE` or `Platform.WEB_DYNAMIC`.', this);
203+
}
202204
}
203205

204206
this.environmentVariables = props.environmentVariables || {};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
import { Platform } from './app';
2+
13
export function renderEnvironmentVariables(vars: { [name: string]: string }) {
24
return Object.entries(vars).map(([name, value]) => ({ name, value }));
35
}
6+
7+
/**
8+
* Utility function to check if the platform is a server-side rendering platform
9+
*/
10+
export function isServerSideRendered(platform?: Platform): boolean {
11+
return platform === Platform.WEB_COMPUTE || platform === Platform.WEB_DYNAMIC;
12+
}

0 commit comments

Comments
 (0)