@@ -3,7 +3,7 @@ import { InternalAxiosRequestConfig, AxiosRequestHeaders, AxiosResponse } from '
33import { handleRequest } from './cache' ;
44import { Stack as StackClass } from './stack' ;
55import { Policy , StackConfig } from './types' ;
6- import { getHost } from './utils' ;
6+ import * as Utility from './utils' ;
77export * as Utils from '@contentstack/utils' ;
88
99let version = '{{VERSION}}' ;
@@ -40,7 +40,7 @@ export function stack(config: StackConfig): StackClass {
4040 live_preview : { } as any
4141 } ;
4242
43- defaultConfig . defaultHostname = config . host || getHost ( config . region , config . host ) ;
43+ defaultConfig . defaultHostname = config . host || Utility . getHost ( config . region , config . host ) ;
4444 config . host = defaultConfig . defaultHostname ;
4545
4646 if ( config . apiKey ) {
@@ -59,6 +59,21 @@ export function stack(config: StackConfig): StackClass {
5959 throw new Error ( 'Environment for Stack is required' ) ;
6060 }
6161
62+ if ( config . live_preview ) {
63+ if ( Utility . isBrowser ( ) ) {
64+ const params = new URL ( document . location . toString ( ) ) . searchParams ;
65+ if ( params . has ( 'live_preview' ) ) {
66+ config . live_preview . live_preview = params . get ( 'live_preview' ) || config . live_preview . live_preview ;
67+ }
68+ if ( params . has ( 'release_id' ) ) {
69+ defaultConfig . headers [ 'release_id' ] = params . get ( 'release_id' ) ;
70+ }
71+ if ( params . has ( 'preview_timestamp' ) ) {
72+ defaultConfig . headers [ 'preview_timestamp' ] = params . get ( 'preview_timestamp' ) ;
73+ }
74+ }
75+ }
76+
6277 if ( config . branch ) {
6378 defaultConfig . headers . branch = config . branch ;
6479 }
0 commit comments