diff --git a/infra/cloud-url-stack.ts b/infra/cloud-url-stack.ts index 2d21d3c..6025ad0 100644 --- a/infra/cloud-url-stack.ts +++ b/infra/cloud-url-stack.ts @@ -12,10 +12,10 @@ import {HttpOrigin} from "aws-cdk-lib/aws-cloudfront-origins"; import {OutputSet} from "./constructs/output-set"; import {CfnLogGroup, LogGroup, RetentionDays} from "aws-cdk-lib/aws-logs"; import {readFileSync} from "fs"; -import {readLinksFromFile} from "./utils"; +import {default as links} from '../links.json'; export type LinkRecords = { - [key: string]: string | { url: string, expiresAt: string } + [key: string]: string | { url: string, expiresAt: string|null } }; type CloudUrlStackProps = StackProps & { @@ -29,7 +29,7 @@ export class CloudUrlStack extends Stack { constructor(scope: Construct, id: string, props?: CloudUrlStackProps) { if (props?.stage == null) { - throw new Error('Stage not set'); + throw new Error('stage context value not set'); } super(scope, id, { @@ -50,8 +50,6 @@ export class CloudUrlStack extends Stack { const logGroup = this.createLogGroup(functionName); - const links = readLinksFromFile(); - const redirectFn = this.createRedirectFunction(functionName, logGroup, links); const distribution = this.createDistribution(redirectFn); diff --git a/infra/utils.ts b/infra/utils.ts deleted file mode 100644 index 228420c..0000000 --- a/infra/utils.ts +++ /dev/null @@ -1,33 +0,0 @@ -import {readFileSync} from "fs"; -import {LinkRecords} from "./cloud-url-stack"; -import Ajv from "ajv"; - -export function readLinksFromFile(): LinkRecords { - const data = JSON.parse(readFileSync('./links.json').toString()); - - const schema = { - type: 'object', - additionalProperties: { - type: ['string', 'object'], - properties: { - url: { - type: 'string', - }, - expiresAt: { - type: ['null', 'string'], - }, - }, - required: ['url'], - additionalProperties: false - }, - }; - - const ajv = new Ajv(); - const validate = ajv.compile(schema); - const valid = validate(data); - if (!valid) { - throw new Error(`Failed to validate links.json\n${JSON.stringify(validate.errors, null, 4)}`); - } - - return data as LinkRecords; - } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 8aad544..2d37d65 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,6 @@ "name": "cloud-url", "version": "0.1.0", "dependencies": { - "ajv": "^8.17.1", "aws-cdk-lib": "2.135.0", "constructs": "^10.0.0", "source-map-support": "^0.5.21" @@ -1169,21 +1168,6 @@ "node": ">=0.4.0" } }, - "node_modules/ajv": { - "version": "8.17.1", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.17.1.tgz", - "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", - "dependencies": { - "fast-deep-equal": "^3.1.3", - "fast-uri": "^3.0.1", - "json-schema-traverse": "^1.0.0", - "require-from-string": "^2.0.2" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/epoberezkin" - } - }, "node_modules/ansi-escapes": { "version": "4.3.2", "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz", @@ -2213,22 +2197,12 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/fast-deep-equal": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", - "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" - }, "node_modules/fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", "dev": true }, - "node_modules/fast-uri": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.0.1.tgz", - "integrity": "sha512-MWipKbbYiYI0UC7cl8m/i/IWTqfC8YXsqjzybjddLsFjStroQzsHXkc73JutMvBiXmOvapk+axIl79ig5t55Bw==" - }, "node_modules/fb-watchman": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/fb-watchman/-/fb-watchman-2.0.2.tgz", @@ -3254,11 +3228,6 @@ "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==", "dev": true }, - "node_modules/json-schema-traverse": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", - "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==" - }, "node_modules/json5": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", @@ -3684,14 +3653,6 @@ "node": ">=0.10.0" } }, - "node_modules/require-from-string": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", - "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/resolve": { "version": "1.22.8", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz", diff --git a/package.json b/package.json index 7f0249d..7aa5787 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,6 @@ "typescript": "~5.4.3" }, "dependencies": { - "ajv": "^8.17.1", "aws-cdk-lib": "2.135.0", "constructs": "^10.0.0", "source-map-support": "^0.5.21" diff --git a/tsconfig.json b/tsconfig.json index da6168c..c26d899 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -21,6 +21,8 @@ "experimentalDecorators": true, "strictPropertyInitialization": false, "allowJs": true, + "resolveJsonModule": true, + "esModuleInterop": true, "typeRoots": [ "./node_modules/@types" ]