Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Preview Connectors
import NacelleShopifyConnector from "@nacelle/shopify-connector"
import NacelleContentfulPreviewConnector from "@nacelle/contentful-preview-connector"
export default ({ app }) => {
if (process.env.NACELLE_PREVIEW_MODE) {
if (!process.env.myshopifyDomain) {
throw new Error(
"Couldn't get data from your CMS. Make sure to include NACELLE_SHOPIFY_DOMAIN in your .env file"
)
}
if (!process.env.shopifyToken) {
throw new Error(
"Couldn't get data from your CMS. Make sure to include NACELLE_SHOPIFY_API_KEY in your .env file"
)
}
if (!process.env.NACELLE_CMS_PREVIEW_TOKEN) {
throw new Error(
"Couldn't get data from your CMS. Make sure to include NACELLE_CMS_PREVIEW_TOKEN in your .env file"
)
}
if (!process.env.NACELLE_CMS_PREVIEW_SPACE_ID) {
throw new Error(
"Couldn't get data from your CMS. Make sure to include NACELLE_CMS_PREVIEW_SPACE_ID in your .env file"
)
}
const contentfulConnector = new NacelleContentfulPreviewConnector({
contentfulSpaceID: process.env.NACELLE_CMS_PREVIEW_SPACE_ID,
contentfulToken: process.env.NACELLE_CMS_PREVIEW_TOKEN
})
const shopifyConnector = new NacelleShopifyConnector({
shopifyDomain: process.env.myshopifyDomain.split(".")[0],
shopifyApiKey: process.env.shopifyToken
})
app.$nacelle.data.product = params => shopifyConnector.product(params)
app.$nacelle.data.products = params => shopifyConnector.products(params)
app.$nacelle.data.collection = params => shopifyConnector.collection(params)
app.$nacelle.data.collectionPage = params =>
shopifyConnector.collectionPage(params)
app.$nacelle.data.allProducts = params =>
shopifyConnector.allProducts(params)
app.$nacelle.data.allCollections = params =>
shopifyConnector.allCollections(params)
app.$nacelle.data.content = params => contentfulConnector.content(params)
app.$nacelle.data.pages = params => contentfulConnector.pages(params)
app.$nacelle.data.page = params => contentfulConnector.page(params)
app.$nacelle.data.article = params => contentfulConnector.article(params)
app.$nacelle.data.articles = params => contentfulConnector.articles(params)
app.$nacelle.data.blog = params => contentfulConnector.blog(params)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment