Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add useJSONContent option for express and sveltekit #41

Merged
merged 5 commits into from
Dec 13, 2024

Conversation

CahidArda
Copy link
Collaborator

@CahidArda CahidArda commented Dec 10, 2024

When adding nextjs-pages integration, we realized that the QStash verification would fail because the bodies don't match. After inspection, here is what we saw:

  • triggerFirstInvocation which runs in the client.trigger or in the first workflow endpoint invocation adds content-type: application/json by default.
  • If you send this body: { "test" : "message" }, QStash uses the whole string when creating signature.
  • But nextjs-pages receives {"test":"message"} because of the content-type header.

To fix the issue, we switched to publish in triggerFirstInvocation.

As a result of this however, some frameworks didn't work.

  • In express we only support content-type: application/json currently.
  • Sveltekit would get empty string as body when content-type wasn't application/json.

Copy link

linear bot commented Dec 10, 2024

Comment on lines +223 to +224
* Whether the framework should use `content-type: application/json`
* in `triggerFirstInvocation`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this very confusing because we cannot assume anyone is familiar with our internal workings, they will not know what triggerFirstInvocationis. To me a much more friendly approach would be directly specifying headers that are then forwarded, those can include the content type but are not limited

Copy link
Collaborator Author

@CahidArda CahidArda Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useJSONContent is not part of the options we allow in serve methods for frameworks (see PublicServeOptions). So it won't be visible to users unless they they import serve from the route like import { serve } from "@upstash/workflow"

The reason we need this parameter is because we used to have publishJSON in client.trigger. this didn't work because publishJSON adds content-type: application/json, which breaks some frameworks. So we used publish. But some frameworks still need the content type to be application/json. sveltekit is one of them.

If you have a better alternative to the current implementation we can change it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed useJSONContent from the public API

examples/express/index.ts Outdated Show resolved Hide resolved
examples/express/index.ts Outdated Show resolved Hide resolved
@CahidArda CahidArda merged commit ea280b8 into main Dec 13, 2024
19 checks passed
@CahidArda CahidArda deleted the DX-1470-integrations branch December 13, 2024 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants