I have the following code setup for a 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;
When I test this with localhost
and Postman it works, however when it is live it responds with a 404 error:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot POST /webhook/all</pre>
</body>
</html>
My only guess is it has something to do with my HTTPS
, since the Stripe Docs say this:
If you use an HTTPS URL for your webhook endpoint, Stripe will validate that the connection to your server is secure before sending your webhook data. For this to work, your server must be correctly configured to support HTTPS with a valid server certificate.
My SSL certificate is setup with Let's Encrypt on a DO droplet, and it seems to be working fine, so I'm not sure why this would be the issue though.
Note: I purposefully made event_json
a string, since I am trying to remove as many possible confounding variables as possible. Once this works as a string I will uncomment body-parser
and switch event_json
over to a variable again.