-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (33 loc) · 1.07 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// index.js
const express = require('express');
const bodyParser = require('body-parser');
const axios = require('axios');
const app = express();
// Middleware to parse JSON bodies
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// Serve static files from the 'public' directory
app.use(express.static('public'));
// Route to handle form submission
app.post('/send', async (req, res) => {
const jsonData = req.body.json;
const webhookUrl = req.body.webhook;
try {
// Send JSON data to webhook address
const response = await axios.post(webhookUrl, jsonData, {
headers: {
'Content-Type': 'application/json'
}
});
console.log('Response from webhook:', response.data);
res.send('JSON sent successfully to webhook!');
} catch (error) {
console.error('Error sending JSON to webhook:', error.message);
res.status(500).send('Error sending JSON to webhook');
}
});
// Start the server
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});