|
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 | +} |
4 | 8 |
|
5 | | - // Use the regex to capture the relevant parts of the input URL |
6 | | - const matches = url.match(regex); |
7 | 9 |
|
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_/`; |
26 | 11 | export const MAX_FILE_SIZE = 500000; |
27 | 12 | export const FILES_BUCKET = import.meta.env.VITE_FILES_BUCKET; |
28 | 13 | export const REGION = import.meta.env.VITE_REGION; |
|
0 commit comments