Hello I am using newest remix template version, which doesn’t have web folder or gdpr.js file. I am trying to implement webhooks but notice I don’t have gdpr.js file. Here is my code I thought it might work? But the console doesn’t log anything when I modify product. Anyone have any idea? Thank you!
import "@shopify/shopify-app-remix/adapters/node";
import {
AppDistribution,
DeliveryMethod,
shopifyApp,
LATEST_API_VERSION,
} from "@shopify/shopify-app-remix";
import { PrismaSessionStorage } from "@shopify/shopify-app-session-storage-prisma";
import { restResources } from "@shopify/shopify-api/rest/admin/2023-07";
import prisma from "./db.server";
const shopify = shopifyApp({
apiKey: process.env.SHOPIFY_API_KEY,
apiSecretKey: process.env.SHOPIFY_API_SECRET || "",
apiVersion: LATEST_API_VERSION,
scopes: process.env.SCOPES?.split(","),
appUrl: process.env.SHOPIFY_APP_URL || "",
authPathPrefix: "/auth",
sessionStorage: new PrismaSessionStorage(prisma),
distribution: AppDistribution.AppStore,
restResources,
webhooks: {
PRODUCTS_UPDATE: {
deliveryMethod: DeliveryMethod.Http,
callbackUrl: "/ItemUpdates",
callback: async (topic, shop, body, webhookId) => {
console.log('--- Product update ---');
const payload = JSON.parse(body);
console.log(payload);
console.log('--- /Product update ---');
},
},
APP_UNINSTALLED: {
deliveryMethod: DeliveryMethod.Http,
callbackUrl: "/webhooks",
callback: async (topic, shop, body, webhookId) => {
try {
console.error("Success!");
} catch (error) {
console.error('Error processing APP_UNINSTALLED webhook:', error);
}
},
},
},
hooks: {
afterAuth: async ({ session }) => {
shopify.registerWebhooks({ session });
},
},
...(process.env.SHOP_CUSTOM_DOMAIN
? { customShopDomains: [process.env.SHOP_CUSTOM_DOMAIN] }
: {}),
});
export default shopify;
export const apiVersion = LATEST_API_VERSION;
export const addDocumentResponseHeaders = shopify.addDocumentResponseHeaders;
export const authenticate = shopify.authenticate;
export const login = shopify.login;
export const registerWebhooks = shopify.registerWebhooks;
export const sessionStorage = shopify.sessionStorage;
import { authenticate } from "../shopify.server";
export const action = async ({ request }) => {
const { topic, shop, session } = await authenticate.webhook(request);
switch (topic) {
case "PRODUCTS_UPDATE":
console.log("product update works");
default:
throw new Response("Unhandled webhook topic", { status: 404 });
}
throw new Response();
};