Hello,
Why is my app unable to get the embedded URL and shows a 404 error in the production environment, but after entering the URL multiple times in the browser, it works? Thank you in advance!
A Shopify Remix app is experiencing 404 errors when loading in production’s embedded environment, though the issue resolves after multiple URL entry attempts.
Primary Issue:
Likely Causes Identified:
Recommended Solutions:
@shopify/app-bridge-utilsStatus: Awaiting original poster’s response to troubleshooting suggestions.
Hello,
Why is my app unable to get the embedded URL and shows a 404 error in the production environment, but after entering the URL multiple times in the browser, it works? Thank you in advance!
Hi @ZoeM_1
It sounds like your app is experiencing an issue with how Shopify handles embedded apps and session tokens. The 404 error usually occurs because the app isn’t properly loading the session or embedding itself correctly within Shopify’s iframe. Here are some possible reasons and solutions:
Shopify apps rely on session tokens to authenticate and load the app properly. In production, if the session token isn’t properly set up or refreshed, the app can fail to embed and show a 404. Make sure you’ve implemented Shopify’s session token handling correctly:
import { getSessionToken } from “@shopify/app-bridge-utils”;
// Example usage with App Bridge
const app = createApp({
apiKey: “your-api-key”,
shopOrigin: “your-shop-origin”,
});
getSessionToken(app).then((token) => {
// Use token to authenticate API requests
});
The behavior you described, where entering the URL multiple times eventually works, might be due to browser caching or how cookies are handled. Some browsers, especially when third-party cookies are restricted, might block session cookies.
Solution:
import createApp from “@shopify/app-bridge”;
import Redirect from “@shopify/app-bridge/actions/Redirect”;
const app = createApp({
apiKey: “your-api-key”,
shopOrigin: “your-shop-origin”,
});
const redirect = Redirect.create(app);
redirect.dispatch(Redirect.Action.REMOTE, “your-auth-url”);
In development, Shopify uses localhost or a tunneling service (like Ngrok), which handles sessions differently compared to production. Ensure you’ve accounted for these differences in production:
Sometimes, middleware isn’t configured properly to handle incoming requests in the production environment.
Solution:
To narrow down the issue:
Let me know if you need more clarification or step-by-step guidance. I’m happy to help!
Best regards,
Daisy