2
votes

I'm building a little Shopify app. I wanna add an application proxy. It all works fine - local path causes the redirect to my page.

However if I set the Content-Type: application/liquid header the page should be loaded as a local Shopify page.

But when I do that the browser simply downloads the output rather than displaying it in the context of Shopify theme.

Any ideas what am I doing wrong or what might be causing this?

From Shopify docs:

If the HTTP response from the Proxy URL has Content-Type: application/liquid set in its headers, Shopify will evaluate and render any Liquid code in the request's body in the context of the shop using the shop's theme. When used the right way, it can automatically make your app look like it belongs as part of the shop without any manual intervention.

UPDATE

It seems to be working fine on one server, but keeps downloading on another. Trying to compare the headers with no luck so far.

1
Are you still experiencing this problem?Josh Brown
yes. it works fine on two out of three serversMaGnetas

1 Answers

3
votes

I had this exact same issue. After hours of troubleshooting, I found that it was a directive in my .htaccess file that was causing the issue. This is what it looked like before:

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

When I changed it to the below, the proxy page rendered correctly:

# Redirect Trailing Slashes...    
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/$ /$1 [L,R=301]

Note also that if you're not requesting a file (ex: proxy.php), but using a directory (ex: http://yourdomain.com/proxy) that the request to the server includes the trailing slash (meaning that Shopify's proxy requests http://yourdomain.com/proxy/). The htaccess file issues a 301 redirect, which is forcing Shopify to download the file instead of interpret it as liquid. To fix that issue, you might add another rewrite condition that excludes those domains from being redirect to theire "non-trailing-slash" counterparts.