Shopify - get the domain domain inside the application

I am new to Shopify, and I use Node, Express to internally and react with polaris libaray.

My question is how to get the store domain initiating the request to the application. When I searched, I could only find one that was used in Ruby ShopifyAPI::Shop.current, and am I looking for a similar thing to use in node?

+4
source share
1 answer

See https://github.com/BKnights/kotn-shopify-utils for an example. Yes, it uses a session. The code is quite peculiar. I published it mainly as an easy way to share my own projects, but for them it was very good.

, , - . cookie .

, . validSession, session, middleware

Polaris JS ( dustjs):

      <script type="text/javascript">
    var KotN = {
        shop:'{shop}',
        apiKey: '{apiKey}',
        shopOrigin: 'https://{shop}.myshopify.com',
        locale:'{locale}' || (navigator.languages ? (navigator.language || navigator.languages[0]) : (navigator.userLanguage || navigator.browerLanguage))
    };
  </script>

Polaris :

import * as React from 'react';
import {EmbeddedApp} from '@shopify/polaris/embedded';
import ShopProvider from './stores/ShopProvider';
import  Status from './views/status';


const shop = KotN.shop;
const shopOrigin = KotN.shopOrigin;
const apiKey = KotN.apiKey;

console.log('shop: '+ shop +' and origin: '+ shopOrigin);


export default class MyApp extends React.Component {
  render() {
    return (
      <EmbeddedApp
        apiKey={apiKey}
        shopOrigin={shopOrigin}
        forceRedirect={true}
        debug={true}
      >
        <ShopProvider>
          <Status />
        </ShopProvider>
      </EmbeddedApp>
    );
  }
}
+3

Source: https://habr.com/ru/post/1689682/


All Articles