Comments (10)
Hey there,
I had the same issue and after a few hours of pissing around I finally worked out why it stalls. I'm running a serverless function that had some body parser middleware running. Basically you just need to turn that off.
Under the hood, when you call Shopify.Webhooks.Registry.process()
, the req.on()
event callbacks would be messed up by the body parser and stall the request.
Might not be the exact problem for you, but worth giving it a try.
from shopify-api-js.
It would be great if we didn't need the work around to disable the body parser for this to work. Is this possible at all?
from shopify-api-js.
This issue is mainly because of body parser or express.json() middleware. Try this code to exclude body parser or express.json()
function excludeShopifyWebhookEndpoint(fn) {
return function (req, res, next) {
if (req.path === '/api/webhooks' && req.method === 'POST') {
next();
} else {
fn(req, res, next);
}
}
}
app.use(excludeShopifyWebhookEndpoint(express.json()));
Note: Above solution is applicable for stripe and shopify webhooks :)
from shopify-api-js.
I'm having the same issue : timeout on await Shopify.Webhooks.Registry.register.
Relevant code :
Shopify.Webhooks.Registry.webhookRegistry = [
{
path: "/handleWebhooks",
topic: "APP_UNINSTALLED",
webhookHandler: handleUninstall.bind(this)
},
{
path: "/handleWebhooks",
topic: "THEMES_UPDATE",
webhookHandler: handleThemeChange.bind(this)
}
];
export const handleWebhooks = async (
req: functions.https.Request,
res: functions.Response<any>
) => {
try{
if(!Shopify.Webhooks.Registry.isWebhookPath(req.path)) {
functions.logger.error("not a webhook path", req.path);
return;
}
await Shopify.Webhooks.Registry.process(req, res);
} catch(error) {
functions.logger.error("failed processing webhook", error);
}
}
from shopify-api-js.
@saampotter
Thanks a lot ! After digging a bit in the code, I was suspecting something of that flavor with the req.on callbacks.
The issue is that I'm using firebase functions, so if there is indeed some kind of body parsing, I can't do much about it...
I ended up re-implementing the hmac check and WebhookRegistry.process feature myself, but I'd prefer to stick with the shpify way of things.
from shopify-api-js.
@saampotter I just faced the same issue using body parser as middleware. Did you able to find any workaround ?
from shopify-api-js.
@atiqueahmedziad I simply disabled body parser middleware for the specific webhook route. Ended up implementing the HMAC verification myself because I'm not a fan of the API design of this package.
from shopify-api-js.
+1 for the request to have Shopify.Webhooks.Registry.process not reliant on req.on('end'), which causes it to silently break when using bodyParser or express.json(). (Or, at bare, minimum, to include a warning about this in the documentation! It's a pretty gnarly dependency to not call attention to in the developer onboarding guide)
from shopify-api-js.
router.post('/webhooks', async (ctx) => {
try {
await Shopify.Webhooks.Registry.process(ctx.req, ctx.res);
console.log(`Webhook processed, returned status code 200`);
} catch (error) {
console.log(`Failed to process webhook: ${error}`);
}
});
server.use(bodyParser());
I put the bodyParser
below the route but it still hangs forever.
How can I disable the bodyparser without removing the code line?
from shopify-api-js.
Documentation regarding body parsers here
Note that webhook processing in v6.0.0
will be changing (along with just about everything else!) ... release candidate v6.0.0-rc1
is available.
from shopify-api-js.
Related Issues (20)
- Support accessing Line Item IDs in Active Shopify Subscriptions
- Support pagination when searching customers with admin rest api HOT 1
- Unable to create customer with password using customerCreate on admin API node client HOT 1
- Expose RemixRestClient and GraphQLClient types for @shopify/shopify-app-remix HOT 1
- retries > 3 throws unexpected exception - cannot read properties of undefined (reading 'headers') HOT 8
- Managed Installation is broken when reinstalling from Admin's Settings. HOT 8
- GraphQL Codegen Fails with Multiple Errors When Generating Types for Shopify API HOT 4
- question: product types from rest api HOT 2
- Upgrade to new Shopify API version without upgrading `@shopify/shopify-api` package HOT 1
- Documentation pages return 404 HOT 1
- [API] Invalid API key or access token (unrecognized login or wrong password) Error HOT 3
- It would be great if @shopify/admin-api-client works with Subrequest Profiler out of the box.
- A new release of the Shopify API is due soon HOT 1
- Keep getting INTERNAL_SERVER_ERROR on the response of `productVariantsBulkCreate` query HOT 1
- Shopify afterAuth hook not registering webhooks HOT 3
- NEW BUG: storeAvailability locations missing HOT 2
- Customer deletion error: Disconnected before secure TLS was established HOT 1
- shopify.session.getCurrentId() fails to read request headers from Next.js app router HOT 6
- Delete application recurring charge is not working for the node lib HOT 1
- Timeout for admin rest resources HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shopify-api-js.