File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed
Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change 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 = / ^ h t t p s : \/ \/ ( [ a - z A - Z 0 - 9 - ] + ) \. e x e c u t e - a p i \. l o c a l h o s t \. l o c a l s t a c k \. c l o u d : ( \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 ) ;
226export const MAX_FILE_SIZE = 500000 ;
327export const FILES_BUCKET = import . meta. env . VITE_FILES_BUCKET ;
428export const REGION = import . meta. env . VITE_REGION ;
You can’t perform that action at this time.
0 commit comments