Skip to content

Commit 94b5700

Browse files
Update code to remove express sub-app, add middlewares
1 parent 72241e9 commit 94b5700

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

sample-apps/discounts-tutorial/web/gdpr.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default {
99
*/
1010
CUSTOMERS_DATA_REQUEST: {
1111
deliveryMethod: DeliveryMethod.Http,
12+
callbackUrl: "/api/webhooks",
1213
callback: async (topic, shop, body) => {
1314
const payload = JSON.parse(body);
1415
// Payload has the following shape:
@@ -40,6 +41,7 @@ export default {
4041
*/
4142
CUSTOMERS_REDACT: {
4243
deliveryMethod: DeliveryMethod.Http,
44+
callbackUrl: "/api/webhooks",
4345
callback: async (topic, shop, body) => {
4446
const payload = JSON.parse(body);
4547
// Payload has the following shape:
@@ -68,6 +70,7 @@ export default {
6870
*/
6971
SHOP_REDACT: {
7072
deliveryMethod: DeliveryMethod.Http,
73+
callbackUrl: "/api/webhooks",
7174
callback: async (topic, shop, body) => {
7275
const payload = JSON.parse(body);
7376
// Payload has the following shape:

sample-apps/discounts-tutorial/web/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,17 @@ const DELETE_CODE_MUTATION = `
142142

143143
const app = express();
144144

145-
// Connect the Shopify middleware to the app at '/api'
146-
app.use("/api", shopify.app({ webhookHandlers: GDPRWebhookHandlers }));
145+
// Set up Shopify authentication and webhook handling
146+
app.get(shopify.config.auth.path, shopify.auth.begin());
147+
app.get(
148+
shopify.config.auth.callbackPath,
149+
shopify.auth.callback(),
150+
shopify.redirectToShopifyOrAppRoot()
151+
);
152+
app.post(
153+
shopify.config.webhooks.path,
154+
shopify.processWebhooks({ webhookHandlers: GDPRWebhookHandlers })
155+
);
147156

148157
// All endpoints after this point will require an active session
149158
app.use("/api/*", shopify.validateAuthenticatedSession());

sample-apps/discounts-tutorial/web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"node": ">=16.13.0"
1313
},
1414
"dependencies": {
15-
"@shopify/shopify-app-express": "1.0.0-rc.6",
15+
"@shopify/shopify-app-express": "1.0.0-rc.7",
1616
"@shopify/shopify-app-session-storage-sqlite": "^1.0.0-rc.0",
1717
"compression": "^1.7.4",
1818
"cross-env": "^7.0.3",

sample-apps/discounts-tutorial/web/shopify.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ const shopify = shopifyApp({
1111
api: {
1212
restResources,
1313
},
14+
auth: {
15+
path: "/api/auth",
16+
callbackPath: "/api/auth/callback",
17+
},
18+
webhooks: {
19+
path: "/api/webhooks",
20+
},
1421
// This should be replaced with your preferred storage strategy
1522
sessionStorage: new SQLiteSessionStorage(DB_PATH),
1623
});

0 commit comments

Comments
 (0)