good-idea / sane-shopify

MIT License
212 stars 15 forks source link

fix(server): aws lambda #159

Closed liqueflies closed 3 years ago

liqueflies commented 3 years ago

Fix for aws lambda.

The problem was basically two:

  1. Move from native fetch to cross-fetch (no, isomorphic was not working :/)
  2. When you use webhook in async/await format you must return an object with statusCode and body

🎉

Happy merge, hope you like it 👯 🧦

good-idea commented 3 years ago

Thank you!!

good-idea commented 3 years ago

A second note.. I would expect these errors to throw with the stack trace pointing to the source typescript files, not the compiled JS... is this an AWS-specific thing? (I haven't used lambdas in a while)

liqueflies commented 3 years ago

UPDATED: sorry for wrong package reference.

no changes on types.

liqueflies commented 3 years ago

A second note.. I would expect these errors to throw with the stack trace pointing to the source typescript files, not the compiled JS... is this an AWS-specific thing? (I haven't used lambdas in a while)

I didn't get what you would expect for that...

good-idea commented 3 years ago

I'd expect the stack trace to look like this:

4:53:12 PM: 2020-11-10T15:53:12.187Z    4b7f18b7-99da-4b6a-87e9-1b2edc4a0451    INFO    TypeError: realFetch.call is not a function
    at module.exports (/var/task/src/lambda/onProductUpdate.ts:15:19) <- .ts, not .js

But, this was a fetch-related thing that is resolved anyway! I just want to add some info to the docs about this

good-idea commented 3 years ago

Oops those failed builds are my fault. I'll fix and merge

liqueflies commented 3 years ago

I'd expect the stack trace to look like this:

4:53:12 PM: 2020-11-10T15:53:12.187Z  4b7f18b7-99da-4b6a-87e9-1b2edc4a0451    INFO    TypeError: realFetch.call is not a function
    at module.exports (/var/task/src/lambda/onProductUpdate.ts:15:19) <- .ts, not .js

But, this was a fetch-related thing that is resolved anyway! I just want to add some info to the docs about this

Ok got what you are asking me. I think this is how lambda is bundled. It depends on how you build your lambda, is not something "node nuxt/next server integrated" but is bundled on it's own and minifies code. Maybe it's just webpack configuration stuff.

good-idea commented 3 years ago

I created a new PR to merge this in since it wouldn't let me update yours. Thanks for your work on this!