diff --git a/index.js b/index.js index 3cf2102..af54621 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,7 @@ const colors = require("colors"); const app = express(); app.use(express.urlencoded({ extended: true })); app.use(express.json()); - +app.use(express.static('static')); expressWs(app); const hookEvent = new EventEmitter(); @@ -67,8 +67,11 @@ app.post('/:cid/:hook_id/:hook_token', (req, res) => { res.status(200).json({ status: 'ok' }); }); -app.get('/:cid', (req, res) => { +app.get('/:cid/:hook_id/:hook_token', (req, res) => { const cid = req.params.cid; + const hookId = req.params.hook_id; + const hookToken = req.params.hook_token; + if (!cid) { console.log(`Invalid request: cid is required`.red); return res.status(400).json({ error: 'cid is required' }); @@ -77,7 +80,32 @@ app.get('/:cid', (req, res) => { console.log(`No client connected with cid: ${cid}`.red); return res.status(504).json({ error: 'no client connected' }); } - res.status(200).json({ status: 'ok', message: 'Client is connected and ready to receive your webhooks!' }); + + res.status(200).json({ + status: 'ok', + message: 'Client is connected and ready to receive your webhooks!', + hook_id: hookId, + hook_token: hookToken + }); +}); + +app.get('/:cid', (req, res) => { + const cid = req.params.cid; + + if (!cid) { + console.log(`Invalid request: cid is required`.red); + return res.status(400).json({ error: 'cid is required' }); + } + if (!cidsInUse.has(cid)) { + console.log(`No client connected with cid: ${cid}`.red); + return res.status(504).json({ error: 'no client connected' }); + } + + res.status(200).json({ + status: 'ok', + message: 'Client is connected and ready to receive your webhooks!', + cid: cid + }); }); const PORT = process.env.SERVER_PORT || 3000; diff --git a/static/favicon.ico b/static/favicon.ico new file mode 100644 index 0000000..662aff6 Binary files /dev/null and b/static/favicon.ico differ diff --git a/static/robots.txt b/static/robots.txt new file mode 100644 index 0000000..77470cb --- /dev/null +++ b/static/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: / \ No newline at end of file