我为 webhook 设置了以下代码:
var express = require('express');
var router = express.Router();
var nodemailer = require('nodemailer');
var middleware = require('../middleware');
var stripe = require("stripe")(process.env.SECRET_KEY);
// router.use(require("body-parser").raw({type: "*/*"}));
router.post("/webhook/all", function(req, res) {
// Retrieve the request's body and parse it as JSON
// var event_json = JSON.parse(req.body);
middleware.sendEmail('Webhook Test', 'event_json');
res.sendStatus(200);
});
module.exports = router;
当我使用localhost
Postman 对其进行测试时,它可以工作,但是当它处于活动状态时,它会响应 404 错误:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot POST /webhook/all</pre>
</body>
</html>
我唯一的猜测是它与我HTTPS
有关,因为Stripe Docs是这样说的:
如果您为您的 webhook 端点使用 HTTPS URL,Stripe 将在发送您的 webhook 数据之前验证与您的服务器的连接是否安全。为此,您的服务器必须正确配置为支持具有有效服务器证书的 HTTPS。
我的 SSL 证书是在 DO 液滴上使用 Let's Encrypt 设置的,它似乎工作正常,所以我不确定为什么会出现这个问题。
注意:我故意制作event_json
了一个字符串,因为我试图删除尽可能多的混淆变量。一旦它作为一个字符串工作,我将取消注释body-parser
并再次切换event_json
到一个变量。