Add ability to use some functions in serverless services
Overview
...
Type
- [x] New feature
- [ ] Changes to existing features
Motivation
-
await Shopify.Webhooks.Registry.process(req, res) -
await Shopify.Utils.graphqlProxy(req, res)
These functions will never return in some serverless function service because they do not support request.readable === false request.
Reason
These functions use request.on('data') to read posted data but in serverless services such as firebase functions and AWS lambda w/ API gateway, the body data of the request object have been read before the actual function codes are executed.
example for firebase.
import * as functions from "firebase-functions";
export const test = functions.https.onRequest((req, res) => {
console.log(req.readable); // false
console.log(req.body); // can access full of data
// never be resolved or rejected
await Shopify.Webhooks.Registry.process(req, res);
res.send(200)
});
As the request data is already read, request.on('data') and request.on('end') events which are used in the functions are never fired.
Request
I want the functions to support request whose data is already read.
Example of Shopify.Webhooks.Registry.process
async process(
request: http.IncomingMessage,
response: http.ServerResponse,
): Promise<void> {
let reqBody = '';
if (!request.readable) {
// a logic to handle posted data
} else {
const promise: Promise<void> = new Promise((resolve, reject) => {
request.on('data', (chunk) => {
reqBody += chunk;
});
request.on('end', async () => {
/** a logic to handle posted data **/
}
...
Area
- [ ] Add any relevant
Area: <area>labels to this issue
Checklist
- [x] I have described this feature request in a way that is actionable (if possible)
I did a quick & dirty solution for me to make webhooks working with Firebase Functions. Feel free to use it or do it differently.
https://github.com/FredyC/shopify-node-api/pull/1
In addition to this, some serverless functions (i.e. Azure Functions) don't use the http IncomingMessage or ServerResponse classes for request and response, and so are unable to call the process method at all. Extracting the core verification etc logic into a separate method to be called so we can use our own request wrappers could help.
This issue is stale because it has been open for 90 days with no activity. It will be closed if no further action occurs in 14 days.
Would be nice to have a response from a maintainer, because this is still the issue forcing us to use the fork.
As of v6, we are now reading from the request body, so this should be fix. You can find a migration guide from v5 to v6 here.