-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
61 lines (51 loc) · 1.73 KB
/
server.js
File metadata and controls
61 lines (51 loc) · 1.73 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const express = require('express');
const path = require('path');
const https = require('https');
const app = express();
const PORT = process.env.PORT || 3000;
// Middleware para JSON
app.use(express.json({ limit: '50mb' }));
// Servir arquivos estáticos da pasta raiz
app.use(express.static(__dirname));
// Criar agente HTTPS customizado para resolver problemas de SSL
const httpsAgent = new https.Agent({
keepAlive: false, // Desabilita keep-alive para evitar socket hang up
rejectUnauthorized: true,
timeout: 30000, // Timeout de 30 segundos
});
// Rota proxy para enviar webhooks (evita problemas de CORS)
app.post('/send-webhook', async (req, res) => {
const { url, payload } = req.body;
if (!url || !payload) {
return res.status(400).json({ error: 'URL e payload são obrigatórios' });
}
try {
const fetch = (await import('node-fetch')).default;
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'User-Agent': 'Fluxhook/1.0'
},
body: JSON.stringify(payload),
agent: httpsAgent, // Usa o agente HTTPS customizado
timeout: 30000 // Timeout de 30 segundos
});
if (response.status === 204 || response.ok) {
res.json({ success: true, status: response.status });
} else {
const text = await response.text();
res.status(response.status).json({ error: text });
}
} catch (error) {
console.error('Erro ao enviar webhook:', error);
res.status(500).json({ error: error.message });
}
});
// Rota principal
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
});
app.listen(PORT, () => {
console.log(`🚀 Fluxhook rodando em http://localhost:${PORT}`);
});