Skip to content

Commit 815fe63

Browse files
committed
rewire request urls
1 parent 7eaa4a6 commit 815fe63

File tree

3 files changed

+10
-25
lines changed

3 files changed

+10
-25
lines changed

packages/frontend/src/config.tsx

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,13 @@
1-
const turnToPreviewUrl = (url: string) => {
2-
// Define a regular expression to match the required parts of the input URL
3-
const regex = /^https:\/\/([a-zA-Z0-9-]+)\.execute-api\.localhost\.localstack\.cloud:(\d+)\/([^\/]+)\/(.+)$/;
1+
const getOrigin = () => {
2+
const origin = window.location.origin;
3+
if (origin.indexOf('localhost') !== -1) {
4+
return 'http://localhost:4566';
5+
}
6+
return origin;
7+
}
48

5-
// Use the regex to capture the relevant parts of the input URL
6-
const matches = url.match(regex);
79

8-
// Check if the URL matches the expected pattern
9-
if (matches && matches.length === 5) {
10-
const apiId = matches[1];
11-
const port = matches[2];
12-
const stage = matches[3];
13-
const path = matches[4];
14-
15-
// Construct the transformed URL
16-
const transformedUrl = `http://${window.location.origin}/restapis/${apiId}/${stage}/_user_request_/${path}`;
17-
18-
return transformedUrl;
19-
} else {
20-
// If the input URL doesn't match the expected pattern, return an error message
21-
return 'Invalid input URL';
22-
}
23-
};
24-
25-
export const GATEWAY_URL = turnToPreviewUrl(import.meta.env.VITE_GATEWAY_URL);
10+
export const GATEWAY_URL = `${getOrigin()}/restapis/${import.meta.env.VITE_GATEWAY_ID}/prod/_user_request_/`;
2611
export const MAX_FILE_SIZE = 500000;
2712
export const FILES_BUCKET = import.meta.env.VITE_FILES_BUCKET;
2813
export const REGION = import.meta.env.VITE_REGION;

packages/infra/cdk/aws-sdk-js-notes-app-stack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export class AwsSdkJsNotesAppStack extends Stack {
142142
});
143143

144144
new CfnOutput(this, "FilesBucket", { value: filesBucket.bucketName });
145-
new CfnOutput(this, "GatewayUrl", { value: api.url });
145+
new CfnOutput(this, "GatewayId", { value: api.restApiId });
146146
new CfnOutput(this, "IdentityPoolId", { value: identityPool.ref });
147147
new CfnOutput(this, "Region", { value: this.region });
148148
new CfnOutput(this, "FrontendDistributionId", { value: distribution.distributionId });

packages/scripts/populate-frontend-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const isLocal = process.argv.includes("--local");
3535
];
3636
const envContent = `
3737
VITE_FILES_BUCKET=${cdkOutput.FilesBucket}
38-
VITE_GATEWAY_URL=${cdkOutput.GatewayUrl}
38+
VITE_GATEWAY_ID=${cdkOutput.GatewayId}
3939
VITE_IDENTITY_POOL_ID=${cdkOutput.IdentityPoolId}
4040
VITE_REGION=${cdkOutput.Region}
4141
VITE_BASE_URL=/cloudfront/${cdkOutput.FrontendDistributionId}/

0 commit comments

Comments
 (0)