Do proxy HTTP routes only work in production?
Building Shopify app proxy endpoints for secure data transfer. Frontend (theme extension) needs JSON data but receives HTML in all scenarios.
5 Replies
Hello,
App proxies work in all environments. You need to make sure that you've set up the proxy for the corresponding environment that you're working on. For example, a proxy for the environment
development
should have a proxy URL https://someApp--development.gadget.app/someProxySubPath
In development it would be:
https://someApp.gadget.app/someProxySubPath
Thanks for the quick response! We've confirmed the app proxy is set up correctly for development (https://wishlists--development.gadget.app/api/apps/gadget), but we're still getting HTML responses instead of JSON from our routes.
What we're seeing:
Frontend request:
GET https://camphollow.com/apps/gadget/chatbot-session
Status: 200 OK
But the response body is HTML:
SyntaxError: Unexpected token '<', "<html lang"... is not
valid JSON
Backend logs show:
request completed
res: {"statusCode":200}
responseTime: 67.70195199968293
url: /api/apps/gadget/chatbot...
Our route at
/api/routes/apps/gadget/GET-chatbot-session.js:
const route = async ({ request, reply, api, logger }) => {
logger.info('[Apps/Gadget] Route executed'); // This
never logs
await reply.send({ success: true });
};
export default route;
The route handler never executes - we don't see our log
messages, but Gadget returns 200 with HTML content (appears
to be the dev harness with Vite scripts).
Why would routes return HTML instead of executing
in development? Is there a specific configuration or sync
process we're missing?
---
This clearly shows them that the route exists, the proxy is
working (200 status), but the handler isn't executing.
https://wishlists--development.gadget.app/api/apps/gadget doesn't exist in your backend so you're being returned the default unauthenticated page
Do you mind sharing what route you're trying to hit in the Gadget backend?
I'm specifically talking about this subpath:
api/apps/gadget
There's no corresponding route in the routes
folderyeah sure so we have : api/routes/proxy/GET-chatbot-session.js is the endpoint
In our TOML we have: [app_proxy]
url = "https://wishlists--development.gadget.app/api/proxy"
subpath = "gadget"
prefix = "apps"
Remove
api
from your url
definition and then you should be able to hit the route (granted you're hitting the correct path for the proxy via the storefront - https://someShopName.myshopify.com/apps/someSubPath)