-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: move to OAC in static-website and fix issue with runtime-config …
…not updating (#894)
- Loading branch information
Showing
4 changed files
with
1,098 additions
and
1,087 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/*! Copyright [Amazon.com](http://amazon.com/), Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 */ | ||
import { CfnJson, Lazy, Token } from "aws-cdk-lib"; | ||
import { Construct } from "constructs"; | ||
|
||
const isUnresolved = (value: any) => | ||
Token.isUnresolved(value) || | ||
(typeof value === "string" && value.endsWith("}}")); | ||
|
||
const resolveTokens = (scope: Construct, payload: any) => { | ||
const _runtimeConfig: Record<string, any> = {}; | ||
|
||
Object.entries(payload).forEach(([key, value]) => { | ||
if (isUnresolved(value)) { | ||
_runtimeConfig[key] = new CfnJson(scope, `runtimeConfig-${key}`, { | ||
value, | ||
}).value; | ||
} else if (typeof value === "object") { | ||
_runtimeConfig[key] = resolveTokens(scope, value); | ||
} else if (Array.isArray(value)) { | ||
_runtimeConfig[key] = value.map((v) => resolveTokens(scope, v)); | ||
} else { | ||
_runtimeConfig[key] = value; | ||
} | ||
}); | ||
|
||
return _runtimeConfig; | ||
}; | ||
|
||
export const lazilyRender = (scope: Construct, payload: any) => | ||
Lazy.any({ | ||
produce: () => resolveTokens(scope, payload), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.