Does anyone have an example of serving a JS file using App Proxy?

Ayush_Gupta
Shopify Partner
3 0 0

Does anyone have an example of serving a JS file using App Proxy?

Replies 9 (9)

KarlOffenberger
Shopify Partner
1873 184 900

Hi Ayush,

An example using what? Node.js? Ruby? .NET? PHP? Too broad of a question.

You'd serve the JS file by setting the response content-type to text/javascript. Or serve text/html and a script tag with the JS from some CDN or your own server.

Otherwise google examples on Github and you shall find.

Hope this helps!

KarlOffenberger
Shopify Partner
1873 184 900

And beware the HTTP proxies have been deprecated as noted here. Must use HTTPS.

Ayush_Gupta
Shopify Partner
3 0 0

Thanks, Karl. I am able to return the javascript file to Shopify app using Node.js proxy.

But the file I am trying to send is a service-worker which is not being sent as a worker file but a normal JS file. Do you have any idea how to send worker file from proxy server? 

KarlOffenberger
Shopify Partner
1873 184 900

I don't have practical experience with app proxies, even less so in that combination you're attempting, but a few pointers regarding service workers

  1. You'll need to register the service worker and beware of how or specifically from what path you do so because that will limit the scope of the service worker
  2. Will the init script also be served via app proxy?
  3. You'll need loads of patience and nerves of steel if the service worker installation fails

Either way, sounds like an interesting approach. Sorry I cannot be of more help here - if you walk down untrodden paths, you must be prepared to get lost sometimes 😉

Best wishes!

Ayush_Gupta
Shopify Partner
3 0 0

Thanks, Karl. I am able to server the SW through the proxy and register it. Just running into few unknows, will keep trying and update here if need any more help.

LeadDynoMike
Tourist
5 0 3

Related to this, does anyone know how to know if the merchant changed the app proxy settings?

 

We are using the App Proxy to serve a script on the store front, and right now we hard code the path to our chosen sub path prefix and sub path, but the merchant can change these settings from the apps details page. If a merchant were to change this for our app, the script tag would no longer function, breaking our entire app.

 

It would be at least nice to have a webhook when the merchant changes this, so we can dynamically update our injected script tag on their store, but looking at the webhook docs, I don't see an event that would provide this information.

HunkyBill
Shopify Expert
4845 60 547

@LeadDynoMike wrote:

Related to this, does anyone know how to know if the merchant changed the app proxy settings?

 

We are using the App Proxy to serve a script on the store front, and right now we hard code the path to our chosen sub path prefix and sub path, but the merchant can change these settings from the apps details page. If a merchant were to change this for our app, the script tag would no longer function, breaking our entire app.

 

It would be at least nice to have a webhook when the merchant changes this, so we can dynamically update our injected script tag on their store, but looking at the webhook docs, I don't see an event that would provide this information.


It is troubling. If the client (a merchant) changes things (the proxy jazz in the App View Details), by all rights that should just be their privilege to change a decoration right? In reality, I have seen that if that changes, it breaks the proxy. And there is no notification. And if you have them reset it, updates do not stick, only a complete delete and re-install of the App. But hey, that was in the past! Maybe today, it all actually works! You can test and decide for yourself.

 

Note that App Proxy has received little love over the years, and therefore some of it is still pretty much raw beta in implementation, someone's thoughts and dreams from nearly a decade ago!

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
Razvan_Dobre
Shopify Partner
3 0 0

@LeadDynoMike wrote:

Related to this, does anyone know how to know if the merchant changed the app proxy settings?

 

We are using the App Proxy to serve a script on the store front, and right now we hard code the path to our chosen sub path prefix and sub path, but the merchant can change these settings from the apps details page. If a merchant were to change this for our app, the script tag would no longer function, breaking our entire app.

 

It would be at least nice to have a webhook when the merchant changes this, so we can dynamically update our injected script tag on their store, but looking at the webhook docs, I don't see an event that would provide this information.

 

I do this. When the app installs, I save in my database the path_prefix for that shop. Then I add the version of ScriptTag js that uses that path_prefix. And then, on an App Proxy page, I check that the path_prefix I get from Shopify stayed the same with the one I have in the database. If it is different, I remove the old ScriptTag and add the new one (that has the correct path_prefix inside) and update the database.

bergen
Shopify Partner
17 2 5

I would love to learn more about how to do this. There are two steps here that I have no clue how to do. 

1. discover that the prefix has been changed in a timely fashion. A webhook would be great.

2. query for the current status of the path prefix

If anyone has solved this and can share details, that would be much appreciated. Until then, I can't rely on hard-coding the URL for the app proxy.