Update webhook-server.js
Browse files- webhook-server.js +7 -4
webhook-server.js
CHANGED
|
@@ -1,19 +1,21 @@
|
|
| 1 |
const http = require('http');
|
| 2 |
-
|
| 3 |
const PORT = process.env.PORT || 7860;
|
| 4 |
const GROQ_API_KEY = process.env.GROQ_API_KEY || '';
|
| 5 |
|
| 6 |
console.log('[CC-Green] Starting...');
|
| 7 |
|
| 8 |
const server = http.createServer((req, res) => {
|
| 9 |
-
|
|
|
|
| 10 |
|
|
|
|
| 11 |
if (req.url === '/health' || req.url === '/') {
|
| 12 |
res.writeHead(200, { 'Content-Type': 'application/json' });
|
| 13 |
-
res.end(
|
| 14 |
return;
|
| 15 |
}
|
| 16 |
|
|
|
|
| 17 |
if (req.url === '/webhook' && req.method === 'POST') {
|
| 18 |
let body = '';
|
| 19 |
req.on('data', function(chunk) { body += chunk; });
|
|
@@ -42,12 +44,13 @@ const server = http.createServer((req, res) => {
|
|
| 42 |
} catch (e) {
|
| 43 |
console.log('Error: ' + e.message);
|
| 44 |
res.writeHead(500);
|
| 45 |
-
res.end(
|
| 46 |
}
|
| 47 |
});
|
| 48 |
return;
|
| 49 |
}
|
| 50 |
|
|
|
|
| 51 |
res.writeHead(404);
|
| 52 |
res.end('Not Found');
|
| 53 |
});
|
|
|
|
| 1 |
const http = require('http');
|
|
|
|
| 2 |
const PORT = process.env.PORT || 7860;
|
| 3 |
const GROQ_API_KEY = process.env.GROQ_API_KEY || '';
|
| 4 |
|
| 5 |
console.log('[CC-Green] Starting...');
|
| 6 |
|
| 7 |
const server = http.createServer((req, res) => {
|
| 8 |
+
const ts = new Date().toISOString();
|
| 9 |
+
console.log('[' + ts + '] ' + req.method + ' ' + req.url);
|
| 10 |
|
| 11 |
+
// Health check
|
| 12 |
if (req.url === '/health' || req.url === '/') {
|
| 13 |
res.writeHead(200, { 'Content-Type': 'application/json' });
|
| 14 |
+
res.end('{"status":"healthy","service":"cc-green"}');
|
| 15 |
return;
|
| 16 |
}
|
| 17 |
|
| 18 |
+
// Webhook from Cloudflare
|
| 19 |
if (req.url === '/webhook' && req.method === 'POST') {
|
| 20 |
let body = '';
|
| 21 |
req.on('data', function(chunk) { body += chunk; });
|
|
|
|
| 44 |
} catch (e) {
|
| 45 |
console.log('Error: ' + e.message);
|
| 46 |
res.writeHead(500);
|
| 47 |
+
res.end('{"error":"' + e.message + '"}');
|
| 48 |
}
|
| 49 |
});
|
| 50 |
return;
|
| 51 |
}
|
| 52 |
|
| 53 |
+
// 404
|
| 54 |
res.writeHead(404);
|
| 55 |
res.end('Not Found');
|
| 56 |
});
|