Created
August 2, 2022 18:32
-
-
Save dustinknopoff/4c435a65c4ab50a79c6cd0475bac168d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const bodyParser = require('body-parser'); | |
const ngrok = require('ngrok'); | |
const axios = require('axios'); | |
const crypto = require('crypto'); | |
const PORT = 3000; | |
const app = express(); | |
const passcode = crypto.randomBytes(48).toString('hex'); | |
app.use(bodyParser.json()); | |
app.post('/', async (request, response) => { | |
if (request.body.passcode === passcode) { | |
const { file_name, timestamp, file_key } = request.body | |
console.log(`${file_name} was updated at ${timestamp}`); | |
response.sendStatus(200); | |
} else { | |
response.sendStatus(403); | |
} | |
}) | |
app.listen(PORT, () => console.log(`🚀 Server running on port ${PORT}`)); | |
ngrok.connect(PORT).then(async (endpoint) => { | |
const response = await axios({ | |
url: "https://api.figma.com/v2/webhooks", | |
method: "POST", | |
headers: { | |
'X-Figma-Token': process.env.FIGMA_TOKEN, | |
}, | |
data: { | |
event_type: 'FILE_VERSION_UPDATE', | |
team_id: 'TODO', | |
passcode, | |
endpoint | |
} | |
}) | |
console.log(`🎣 Webhook ${response.data.id} successfully created`) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment