Created
November 6, 2020 21:24
-
-
Save savchukoleksii/53ba57b9d84c24bc58104bbedca72200 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const domain = await fetch(`https://${config.store}/admin/api/2020-07/shop.json?fields=domain`, { | |
method: "GET", | |
headers: { | |
'X-Shopify-Access-Token': config.password, | |
'Content-Type': 'application/json', | |
mode: 'cors', | |
cache: 'no-cache', | |
credentials: 'same-origin', | |
redirect: 'follow', | |
referrerPolicy: 'no-referrer', | |
} | |
}).then(response => response.json()).then(response => response.shop.domain); | |
let original_preview_url = `https://${domain ? domain : config.store}/?preview_theme_id=${config["theme_id"]}`;; | |
let cookies = await fetch(original_preview_url, { | |
method: 'GET', | |
redirect: 'follow', | |
}).then(response => response.headers.get("set-cookie")); | |
const preview_bar_url = `https://${domain ? domain : config.store}/preview_bar?preview_theme_id=${config["theme_id"]}`; | |
let preview_url = (await axios({ | |
method: 'get', | |
url: preview_bar_url, | |
responseType: "html", | |
headers: { | |
Cookie: cookies | |
} | |
}).then(response => response.data).then(html => html.match(/(https:|http:)\/\/[\w\-\d]+\.shopifypreview\.com/gm))).shift(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment