- This topic is empty.
-
AuthorPosts
-
November 22, 2017 at 3:23 am #9559bknightsParticipant
For examples check out https://github.com/BKnights/kotn-shopify-utils
Yes it uses a session.
The code is pretty idiosyncratic. I published it mostly as an easy way to share between my own projects but it’s worked pretty well for those.If you use this where you may scale your servers you’d need to replace the session engine with something more distributed. Cookie sessions work.
This expects to route the setup page of the app to /preferences. Look at that route with the
validSession, session,
middlewareFor passing the domain to Polaris I put the shop info into a plain JS object on the containing page (it’s a dustjs template):
<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>
and then the Polaris component looks like:
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> ); } }
November 22, 2017 at 10:24 am #9556user8081170ParticipantI’m new to Shopify app developing and I’m using Node,Express for the back-end and react with polaris libaray.
My question is how to get the shop’s domain the request is initiating throug h the app. When I searched I could only found one used in Ruby
ShopifyAPI::Shop.current
and I’m looking for the similar thing to use in node?August 8, 2022 at 12:19 pm #9558hazaaaParticipantI know this is a old thread but i’ve stumbled here while i was searching for the answer and just wanted to share my solution with you guys that also have the same problem. This is how i’m getting shop domain.
let shopDomain = new URL(window.location).searchParams.get("shop");
October 30, 2023 at 9:35 am #9557sahil-parmarParticipantAfter all of these years I think it will be easy to get the Shop domain from the below method
new URLSearchParams(location.search).get('shop')
This code snippet will get you the Shop domain of the currently installed shop.
-
AuthorPosts
- You must be logged in to reply to this topic.