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

feat(tjs): Set Content-Length header #1443

Merged
merged 1 commit into from Mar 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions packages/skill-api/src/core/services/process-stripe-webhook.ts
Expand Up @@ -68,9 +68,11 @@ export async function receiveInternalStripeWebhooks({
})
} catch (error: any) {
console.log(
`webhook/stripe-internal error: ${
(error.message, JSON.stringify(event), JSON.stringify(body))
}`,
`webhook/stripe-internal error: ${{
message: error.message,
event: JSON.stringify(event),
body: JSON.stringify(body),
}}`,
)

return {
Expand Down Expand Up @@ -152,16 +154,20 @@ export async function receiveStripeWebhooks({
})
.parse(process.env.TJS_SKILL_SECRET)

const payloadString = JSON.stringify({event})
const contentLength = Buffer.byteLength(payloadString, 'utf8')

const headers = new Headers({
'Content-Type': 'application/json',
'x-skill-secret': skillSecret,
'Content-Length': contentLength.toString(),
})

// not awaiting the fetch so that endpoint can return 200 right away
await fetch(internalStripeWebhookEndpoint, {
method: 'POST',
headers,
body: JSON.stringify({event}),
body: payloadString,
})

return {status: 200, body: `handled by ${targetSiteName}`}
Expand Down