Backend URL in POS UI Extensions

dpavlutin
Shopify Partner
8 0 1

Hello everyone!

 

I'm developing a POS UI Extension that communicates with my Backend server. The only documentation about using a Backend in POS UI extension I found here.

 

During development mode, `shopify app dev` using Cloudflare creates my app URL dynamically. Thus each time the Backend URL is different.

 

How can I access in my POS UI Extension the dynamic URL? Normally I would read `process.env.HOST` (which is set during dev mode), but `process.env` is not available inside POS UI extension.

 

Screenshot 2023-09-02 at 13.17.31.png

 

Thanks!

Replies 2 (2)

dsn
Shopify Partner
8 0 5

Hello,

 

I'm facing same issue. By now, I created a pseudo env file in extensions root in which I define the host url. The file is included in .gitignore so there is no risk to upload it by accident.

 

Within the pseudoenv file, a constant is exported with the url as a string. This constant is imported in the extensions where the fetch url composition is done.

 

I know this is far from being the ideal solution, but this way I just have to update the host one time to keep all my extensions connected to the backend. Just have to remember to modify the host to the production one when deploying the extensions.

 

dsn_0-1693857260570.pngdsn_1-1693857279979.pngdsn_2-1693857328963.png

Hope this help until we got a final solution from Shopify.

dpavlutin
Shopify Partner
8 0 1

Thanks @dsn ! That's my current approach too. I also dynamically update the pseudo config file with the changing app URL during dev mode.

Seems like that's the workaround until we got a solution from Shopify.