forked from Rathore-Rajpal/Superbot-Demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.mjs
More file actions
34 lines (30 loc) · 939 Bytes
/
proxy.mjs
File metadata and controls
34 lines (30 loc) · 939 Bytes
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
import express from 'express';
import fetch from 'node-fetch';
import cors from 'cors';
const app = express();
const PORT = 5001;
app.use(cors());
app.use(express.json());
app.post('/api/forward-chat', async (req, res) => {
try {
const response = await fetch('https://n8nautomation.site/webhook/cf1de04f-3e38-426c-89f0-3bdb110a5dcf', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(req.body)
});
const text = await response.text();
let data;
try {
data = JSON.parse(text);
} catch (e) {
data = text;
}
console.log('N8N webhook status:', response.status);
console.log('N8N webhook response:', data);
res.status(response.status).send(text);
} catch (err) {
console.error('Proxy error:', err);
res.status(500).send('Proxy error');
}
});
app.listen(PORT, () => console.log(`Proxy server running on port ${PORT}`));