Created
June 12, 2020 20:47
-
-
Save LukvonStrom/21ab25792a059a7a782d1f4b226e56a2 to your computer and use it in GitHub Desktop.
Webhook to Websocket Proxy (useful to redirect HTTP Webhooks to devices behind a NAT i.e. Raspberry PIs) - expects at least the minimum JSON outlined in body-min.json as Body - additional attributes are of course addable
This file contains 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
{ | |
"secret": "test", | |
"service": "IFTTT", | |
"event": "button" | |
} |
This file contains 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 app = express(); | |
const http = require('http').createServer(app); | |
const io = require('socket.io')(http, {pingInterval:15000}); | |
app.use(bodyParser.json()); | |
app.set('trust proxy', true); | |
let processSecret = 'test'; | |
app.all('/:service', (req, res) => { | |
let {secret, service} = req.body; | |
if(secret === processSecret){ | |
io.emit(service.toLowerCase(), req.body); | |
} | |
res.json({received: true}); | |
}); | |
http.listen(61345); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment