Skip to content

Commit 7eaa4a6

Browse files
committed
remap gateway url
1 parent 076a5e5 commit 7eaa4a6

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

packages/frontend/src/config.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
1-
export const GATEWAY_URL = import.meta.env.VITE_GATEWAY_URL;
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+)\/([^\/]+)\/(.+)$/;
4+
5+
// Use the regex to capture the relevant parts of the input URL
6+
const matches = url.match(regex);
7+
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);
226
export const MAX_FILE_SIZE = 500000;
327
export const FILES_BUCKET = import.meta.env.VITE_FILES_BUCKET;
428
export const REGION = import.meta.env.VITE_REGION;

0 commit comments

Comments
 (0)