@@ -2,26 +2,34 @@ import discoveryConfig from '../../../discovery.config'
22
33const DEFAULT_WEBOPS_ORIGIN = 'https://faststore.vtex.com'
44
5- let origin =
6- process . env . WEBOPS_API_URL ?. trim ( ) . replaceAll ( / \/ + $ / g, '' ) ??
7- DEFAULT_WEBOPS_ORIGIN
8-
9- origin = origin . startsWith ( 'http' ) ? origin : `https://${ origin } `
10-
11- export const publicKeyUrl = new URL (
12- '/api/v1/password-protection/public-key' ,
13- origin
14- )
15-
16- export const protectionStatusUrl = new URL (
17- '/api/v1/password-protection/status' ,
18- origin
19- )
20- protectionStatusUrl . searchParams . set ( 'storeId' , discoveryConfig . api . storeId )
21-
22- export const sessionUrl = new URL ( '/api/v1/password-protection/session' , origin )
23-
24- export const renewUrl = new URL ( '/api/v1/password-protection/renew' , origin )
5+ function getWebopsOrigin ( ) : string {
6+ const hostFromEnv = process . env . WEBOPS_API_URL ?. trim ( ) ?? ''
7+ const hostWithoutTrailingSlash = hostFromEnv . replace ( / \/ + $ / , '' )
8+ const origin =
9+ hostWithoutTrailingSlash . length > 0
10+ ? hostWithoutTrailingSlash
11+ : DEFAULT_WEBOPS_ORIGIN
12+
13+ return / ^ h t t p s ? : \/ \/ / i. test ( origin ) ? origin : `https://${ origin } `
14+ }
15+
16+ export function publicKeyUrl ( ) : URL {
17+ return new URL ( '/api/v1/password-protection/public-key' , getWebopsOrigin ( ) )
18+ }
19+
20+ export function protectionStatusUrl ( ) : URL {
21+ const url = new URL ( '/api/v1/password-protection/status' , getWebopsOrigin ( ) )
22+ url . searchParams . set ( 'storeId' , discoveryConfig . api . storeId )
23+ return url
24+ }
25+
26+ export function sessionUrl ( ) : URL {
27+ return new URL ( '/api/v1/password-protection/session' , getWebopsOrigin ( ) )
28+ }
29+
30+ export function renewUrl ( ) : URL {
31+ return new URL ( '/api/v1/password-protection/renew' , getWebopsOrigin ( ) )
32+ }
2533
2634/** Timeouts for WebOps password-protection calls (middleware / API routes). */
2735export const passwordProtectionTimeouts = {
0 commit comments