change GET to POST, removed /health

This commit is contained in:
cpu
2025-03-28 02:12:52 +01:00
parent 228f4984d8
commit 4f46c1be99
2 changed files with 19 additions and 58 deletions

View File

@@ -213,21 +213,21 @@ app.post('/subscribe', async (req, res) => {
}
});
// --- Flic Webhook Endpoint ---
// Apply Flic-specific authentication ONLY to this route
app.post('/flic-webhook', authenticateFlicRequest, async (req, res) => {
// --- Flic Webhook Endpoint (GET only) ---
// Apply Flic-specific authentication to this route
app.get('/flic-webhook', authenticateFlicRequest, async (req, res) => {
// Get buttonName from Header 'Button-Name' and timestamp from Header 'Timestamp'
const buttonName = req.headers['button-name'];
const timestamp = req.headers['timestamp'];
// Still get click_type from the request body
const { click_type } = req.body;
// Get click_type from query parameter instead of request body
const click_type = req.query.click_type;
console.log(`Received webhook: Button=${buttonName}, Type=${click_type}, Timestamp=${timestamp || 'N/A'}`);
console.log(`Received GET webhook: Button=${buttonName}, Type=${click_type}, Timestamp=${timestamp || 'N/A'}`);
// Basic validation
if (!buttonName || !click_type) {
console.warn(`Webhook Error: Missing Button-Name header or click_type in body`);
return res.status(400).json({ message: 'Bad Request: Missing Button-Name header or click_type in request body' });
console.warn(`Webhook Error: Missing Button-Name header or click_type query parameter`);
return res.status(400).json({ message: 'Bad Request: Missing Button-Name header or click_type query parameter' });
}
const normalizedButtonName = buttonName.toLowerCase(); // Use lowercase for lookup consistency
@@ -272,15 +272,6 @@ app.post('/flic-webhook', authenticateFlicRequest, async (req, res) => {
}
});
// --- Health Check Endpoint ---
app.get('/health', (req, res) => {
res.status(200).json({
status: 'UP',
timestamp: new Date().toISOString(),
subscription_count: Object.keys(subscriptions).length
});
});
// --- Start Server ---
// Use http.createServer to allow graceful shutdown
const server = http.createServer(app);