You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

24 rivejä
792 B

  1. // Helper methods for webhooks
  2. const fs = require('fs-extra');
  3. const App = require('./app');
  4. exports.createHandler = function(name, fn = () => 'handler') {
  5. return async (req, res, next) => {
  6. const action = await fn(req, res, next);
  7. if (typeof action == 'string') {
  8. const path = `app/webhooks/${name}/${action}.json`;
  9. if (fs.existsSync(path)) {
  10. const app = new App(req, res);
  11. let json = await fs.readJSON(path);
  12. return Promise.resolve(app.define(json)).catch(next);
  13. } else {
  14. res.json({error: `No action found for ${action}.`});
  15. // do not return 404 else stripe will retry
  16. //next();
  17. }
  18. }
  19. }
  20. };