Challenge Encountered with Self-Hosted Dockerized Shopify App

Solved

Challenge Encountered with Self-Hosted Dockerized Shopify App

GeorgeStrongg
Tourist
8 0 1

Dear support specialists,

Please help 😿🙏

My team has encountered few difficulties. We've been trying to sortem out for a while, but failed.🤕

Here's our problem:

We have developed our Shopify app specifically for our development shop. This app, which incorporates a theme, is initiated using the Shopify CLI command 'shopify app dev' and functions as an embedded app, seamlessly accessible through admin.shopify.com. However, when attempting to launch the app using the Dockerfile available at https://github.com/Shopify/shopify-app-template-php/blob/main/Dockerfile on our independent server and domain, we are facing certain challenges.

We use .env:

GeorgeStrongg_0-1706112546869.png

 

On the domain itself, we get an error:

Shopify\Utils::sanitizeShopDomain(): Argument #1 ($shop) must be of type string, null given, called in /app/app/Lib/AuthRedirection.php on line 17

 

Also, there are errors on admin.shopify.com when trying to view the embedded app:

GET https://video-review-plugin-dev.eastrelay.com/index.jsx net::ERR_ABORTED 500 (Internal Server Error)

video-review-plugin-dev.eastrelay.com/index.jsx:1 

Failed to load resource: the server responded with a status of 500 (Internal Server Error)

GET https://video-review-plugin-dev.eastrelay.com/dev_embed.js net::ERR_ABORTED 500 (Internal Server Error)

GET https://video-review-plugin-dev.eastrelay.com/index.jsx net::ERR_ABORTED 500 (Internal Server Error)

 

Please explain how to deploy on a self-hosted server, and what Nginx and Docker configs can be used for the successful operation of the Shopify app with our development store.

Accepted Solution (1)

rsping
Shopify Partner
2 1 1

This is an accepted solution.

Good morning George

We've found a solution... Firstly update shopify to the newest verison. Then try to do this:
- Create a .env file with all this information:
PORT=
FRONTEND_PORT=
BACKEND_PORT=
SCROPES=write_products
HOST=
SHOPIFY_API_SECRET=
SHOPIFY_API_KEY=

- Update the shopify.app.toml with the correct application_url etc. 
- Build the dockerfile with the .env file
- Deploy your app

I've also created a docker-compose file:

version: "3.8"

services:
app:
build:
context: .
args:
SHOPIFY_API_KEY: ${SHOPIFY_API_KEY}
ports:
- "8081:8081"
volumes:
- /app/public
- /app/frontend/dist
- ./web:/app
env_file:
- .env
- .env.shopify


Don't forget to define all the authentication endpoints. Also add a fallback route for the frontend which calls the middleware "shopify.installed":

Route::fallback(function (Request $request) {
if (Context::$IS_EMBEDDED_APP && $request->query("embedded", false) === "1") {
if (env("APP_ENV") === "production") {
return file_get_contents(public_path("index.html"));
} else {
return file_get_contents(base_path("frontend/index.html"));
}
} else {
return redirect(Utils::getEmbeddedAppUrl($request->query("host", null)) . "/" . $request->path());
}
})->middleware("shopify.installed");

which then executes EnsureShopifyInstalled.php



I really hope this helps. If there are any questions, just ask. We've finally managed to get it running!

View solution in original post

Replies 3 (3)

rsping
Shopify Partner
2 1 1

We're also experiencing the same issue. Can't get the shopify app to run inside the docker container. 
When running with npm run dev, no errors but sadly only one concurrent connection which causes other problems... Inside the docker we get a lot of 5xx errors or the authentication bearer is missing etc. etc. 

There's absolutely no documentation about this setup nor anything on the internet. Please help us dear shopify team...


EDIT: We're using the DEFAULT Shopify App Template - PHP. No changes!

rsping
Shopify Partner
2 1 1

This is an accepted solution.

Good morning George

We've found a solution... Firstly update shopify to the newest verison. Then try to do this:
- Create a .env file with all this information:
PORT=
FRONTEND_PORT=
BACKEND_PORT=
SCROPES=write_products
HOST=
SHOPIFY_API_SECRET=
SHOPIFY_API_KEY=

- Update the shopify.app.toml with the correct application_url etc. 
- Build the dockerfile with the .env file
- Deploy your app

I've also created a docker-compose file:

version: "3.8"

services:
app:
build:
context: .
args:
SHOPIFY_API_KEY: ${SHOPIFY_API_KEY}
ports:
- "8081:8081"
volumes:
- /app/public
- /app/frontend/dist
- ./web:/app
env_file:
- .env
- .env.shopify


Don't forget to define all the authentication endpoints. Also add a fallback route for the frontend which calls the middleware "shopify.installed":

Route::fallback(function (Request $request) {
if (Context::$IS_EMBEDDED_APP && $request->query("embedded", false) === "1") {
if (env("APP_ENV") === "production") {
return file_get_contents(public_path("index.html"));
} else {
return file_get_contents(base_path("frontend/index.html"));
}
} else {
return redirect(Utils::getEmbeddedAppUrl($request->query("host", null)) . "/" . $request->path());
}
})->middleware("shopify.installed");

which then executes EnsureShopifyInstalled.php



I really hope this helps. If there are any questions, just ask. We've finally managed to get it running!

GeorgeStrongg
Tourist
8 0 1

Wow! Thanks mate, really appreciate your help. Gonna try this now.