Stripe 웹후크의 오류율은 ~90%이며 예측할 수 없는 응답입니다. 서버 문제?

Stripe 웹후크의 오류율은 ~90%이며 예측할 수 없는 응답입니다. 서버 문제?

처음으로 Stripe 웹훅을 설정하고 있습니다. 수백 건의 테스트 요청을 했는데 오류율이 약 90%였습니다. 실패가 발생하는 이유는 예측할 수 없습니다.

Stripe 대시보드의 실패 응답은 다음 중 하나입니다.

Timed out connecting to remote host

또는

Failed to connect to remote host

내 웹훅(테스트를 위해 단순화했습니다). 대략 10%의 경우 다음과 같이 200개의 응답을 받습니다 {received: true}.

expressRouter.route('/hooks').post( async (req, res) => {

  const event = req.body;

  console.log("Event:");
  console.log(event);

  // Handle the event
  switch (event.type) {
    case 'payment_intent.succeeded':
      const paymentIntent = event.data.object;
      // Then define and call a method to handle the successful payment intent.
      // handlePaymentIntentSucceeded(paymentIntent);
      break;
    case 'payment_method.attached':
      const paymentMethod = event.data.object;
      // Then define and call a method to handle the successful attachment of a PaymentMethod.
      // handlePaymentMethodAttached(paymentMethod);
      break;
    // ... handle other event types
    default:
      console.log(`Unhandled event type ${event.type}`);
  }

  // Return a response to acknowledge receipt of the event
  res.json({received: true});
})

나는 비동기를 사용하거나 사용하지 않고 후크를 정의하는 다음 두 가지 방법을 시도했습니다.

expressRouter.route('/hooks').post( async (req, res) => {
  ...
})
// and 
app.post("/hooks", async (req, res) => {
  ...
})

저는 Stripe 지원팀에 연락하여 그들의 제안을 모두 시도해 보았습니다. 그들은 나에게 다음과 같은 가능성을 남겼습니다.

네트워크 속도가 느리거나 라우팅에 다른 문제가 있을 수 있습니다.

호스트 공급자는 Stripe의 배달 IP 주소도 허용해야 할 수 있습니다. 참고로 서버에 도달하기 전에 차단될 수 있습니다.

Stripe의 IP를 iptables에 추가했습니다. 예:

iptables -I INPUT -p tcp -s 3.18.12.63 -j ACCEPT

Ubuntu 18.04에서 Caddy를 사용하여 Hostinger VPS 서버를 실행하고 있습니다. 내 서버 설정에 문제가 있을 수 있나요? 어떤 조언이라도 대단히 감사하겠습니다.

답변1

효과가 있는 것 같아요.

apt를 통해 ngrok를 설치했습니다(https://ngrok.com/download)

그런 다음 youtube.com/watch?v=S1uExj7mMgM&ab_channel=Twilio를 따르고 ngrok가 localhost:4000으로 전달되도록 설정합니다.

ngrok http 4000

방금 많은 요청을 보냈는데 모두 성공했습니다. 이것이 어떻게 작동하는지, 왜 필요한지 잘 모르겠지만 작동하게 되어 매우 기쁩니다. 이것이 없으면 작동하지 않는 이유를 설명할 수 있는 사람이 있으면 알려주세요!

관련 정보