Skip to content

Instantly share code, notes, and snippets.

@LukvonStrom
Created June 12, 2020 20:47
Show Gist options
  • Save LukvonStrom/21ab25792a059a7a782d1f4b226e56a2 to your computer and use it in GitHub Desktop.
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
{
"secret": "test",
"service": "IFTTT",
"event": "button"
}
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