Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express');
- const fs = require('fs');
- const mkdirp = require('mkdirp');
- const path = require('path');
- const app = express();
- const port = 8001;
- console.log("TESTING", path.join('', ''));
- app.use(express.static('public'));
- const validateSignature = require('./crypto').validateSignature;
- app.use(express.json());
- app.get('/test', (req, res) => {
- res.status(200).send("OK");
- res.end();
- })
- app.post('/webhook-receiver', (req, res) => {
- const signature = req.get('X-Vev-Signature');
- // verify signature
- const isValidSignature = true
- if (isValidSignature === false) {
- // do something here
- return;
- }
- // parse payload
- const payload = req.body.payload;
- console.log("GOT PAYLOAD", payload);
- res.status(200).send("OK");
- res.end();
- return;
- if (req.body.event === 'PUBLISH') {
- payload.pages.forEach(page => {
- const location = path.join('./public', page.index ? 'index' : page.path);
- if (page.index) {
- // is index.html page
- fs.writeFileSync(location + '.html', page.html);
- } else {
- // create folder for location and create file inside folder.
- mkdirp.sync(location);
- fs.writeFileSync(location + '/index.html', page.html);
- }
- });
- }
- res.send({ message: 'I received your webhook!!' });
- });
- app.listen(port, () => console.log(`Example app listening on port ${port}!`));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement