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?

0 Likes
KarlOffenberger
Shopify Partner
1867 182 777

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!

Liked this post? You might also like our fantastic upsell apps Candy Rack and Candy Cart or offer free gifts with Gift Box. All made with ❤️  and care by Digismoothie
KarlOffenberger
Shopify Partner
1867 182 777

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

Liked this post? You might also like our fantastic upsell apps Candy Rack and Candy Cart or offer free gifts with Gift Box. All made with ❤️  and care by Digismoothie
0 Likes
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? 

0 Likes
KarlOffenberger
Shopify Partner
1867 182 777

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!

Liked this post? You might also like our fantastic upsell apps Candy Rack and Candy Cart or offer free gifts with Gift Box. All made with ❤️  and care by Digismoothie
0 Likes
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.

0 Likes
LeadDynoMike
Tourist
5 0 2

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.

0 Likes
HunkyBill
Shopify Expert
4359 36 462

@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
0 Likes
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.

0 Likes
bergen
Shopify Partner
17 2 2

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.

0 Likes