Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const express = require('express');
  2. const fs = require('fs');
  3. const mkdirp = require('mkdirp');
  4. const path = require('path');
  5. const app = express();
  6. const port = 8001;
  7.  
  8. console.log("TESTING", path.join('', ''));
  9.  
  10. app.use(express.static('public'));
  11. const validateSignature = require('./crypto').validateSignature;
  12. app.use(express.json());
  13. app.get('/test', (req, res) => {
  14.     res.status(200).send("OK");
  15.     res.end();
  16. })
  17. app.post('/webhook-receiver', (req, res) => {
  18.   const signature = req.get('X-Vev-Signature');
  19.  
  20.   // verify signature
  21.     const isValidSignature = true
  22.  
  23.   if (isValidSignature === false) {
  24.   // do something here
  25.   return;
  26.   }
  27.   // parse payload
  28.   const payload = req.body.payload;
  29.   console.log("GOT PAYLOAD", payload);
  30.   res.status(200).send("OK");
  31.   res.end();
  32.   return;
  33.   if (req.body.event === 'PUBLISH') {
  34.     payload.pages.forEach(page => {
  35.       const location = path.join('./public', page.index ? 'index' : page.path);
  36.       if (page.index) {
  37.         // is index.html page
  38.         fs.writeFileSync(location + '.html', page.html);
  39.        } else {
  40.         // create folder for location and create file inside folder.
  41.         mkdirp.sync(location);
  42.         fs.writeFileSync(location + '/index.html', page.html);
  43.      }
  44.     });
  45.   }
  46.   res.send({ message: 'I received your webhook!!' });
  47. });
  48. app.listen(port, () => console.log(`Example app listening on port ${port}!`));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement