Delete server.js
Browse files
server.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
| 1 |
-
const express = require('express');
|
| 2 |
-
const cors = require('cors');
|
| 3 |
-
const { db } = require('./src/firebase');
|
| 4 |
-
const axios = require('axios'); // Import axios
|
| 5 |
-
require('dotenv').config();
|
| 6 |
-
|
| 7 |
-
const app = express();
|
| 8 |
-
const PORT = process.env.PORT || 7860;
|
| 9 |
-
|
| 10 |
-
app.use(cors());
|
| 11 |
-
app.use(express.json());
|
| 12 |
-
|
| 13 |
-
// --- HELPER: Telegram Notification ---
|
| 14 |
-
const sendTelegramAlert = async (data) => {
|
| 15 |
-
const token = process.env.TELEGRAM_BOT_TOKEN;
|
| 16 |
-
const chatId = process.env.TELEGRAM_CHAT_ID;
|
| 17 |
-
|
| 18 |
-
if (!token || !chatId) {
|
| 19 |
-
console.warn("β οΈ Telegram credentials missing in .env");
|
| 20 |
-
return;
|
| 21 |
-
}
|
| 22 |
-
|
| 23 |
-
// Format the message nicely
|
| 24 |
-
const message = `
|
| 25 |
-
π *New Lead: House of Ruqa*
|
| 26 |
-
|
| 27 |
-
π€ *Name:* ${data.name}
|
| 28 |
-
π§ *Email:* ${data.email}
|
| 29 |
-
π *Phone:* ${data.phone}
|
| 30 |
-
π¦ *Package:* ${data.packageType}
|
| 31 |
-
|
| 32 |
-
π *Message:*
|
| 33 |
-
${data.message}
|
| 34 |
-
`;
|
| 35 |
-
|
| 36 |
-
try {
|
| 37 |
-
const url = `https://api.telegram.org/bot${token}/sendMessage`;
|
| 38 |
-
await axios.post(url, {
|
| 39 |
-
chat_id: chatId,
|
| 40 |
-
text: message,
|
| 41 |
-
parse_mode: 'Markdown' // Allows bolding
|
| 42 |
-
});
|
| 43 |
-
console.log("βοΈ Telegram Notification Sent");
|
| 44 |
-
} catch (error) {
|
| 45 |
-
console.error("β Telegram Error:", error.response ? error.response.data : error.message);
|
| 46 |
-
}
|
| 47 |
-
};
|
| 48 |
-
|
| 49 |
-
// --- ROUTES ---
|
| 50 |
-
|
| 51 |
-
app.get('/health', (req, res) => {
|
| 52 |
-
res.status(200).json({ status: 'Online', system: 'House of Ruqa Backend' });
|
| 53 |
-
});
|
| 54 |
-
|
| 55 |
-
app.post('/api/lead', async (req, res) => {
|
| 56 |
-
try {
|
| 57 |
-
const { name, email, phone, message, packageType } = req.body;
|
| 58 |
-
|
| 59 |
-
if (!name || !email) {
|
| 60 |
-
return res.status(400).json({ error: 'Name and Email are required.' });
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
const leadData = {
|
| 64 |
-
name,
|
| 65 |
-
email,
|
| 66 |
-
phone: phone || 'N/A',
|
| 67 |
-
message: message || '',
|
| 68 |
-
packageType: packageType || 'General Inquiry',
|
| 69 |
-
timestamp: new Date().toISOString(),
|
| 70 |
-
status: 'new',
|
| 71 |
-
source: 'website_form'
|
| 72 |
-
};
|
| 73 |
-
|
| 74 |
-
// 1. Save to Firebase
|
| 75 |
-
const docRef = await db.collection('leads').add(leadData);
|
| 76 |
-
console.log(`β
New Lead Saved: ${docRef.id}`);
|
| 77 |
-
|
| 78 |
-
// 2. Send Telegram Alert (Async - don't wait for it to respond to user)
|
| 79 |
-
sendTelegramAlert(leadData);
|
| 80 |
-
|
| 81 |
-
res.status(201).json({
|
| 82 |
-
success: true,
|
| 83 |
-
message: 'Request received.',
|
| 84 |
-
id: docRef.id
|
| 85 |
-
});
|
| 86 |
-
|
| 87 |
-
} catch (error) {
|
| 88 |
-
console.error("β Error processing lead:", error);
|
| 89 |
-
res.status(500).json({ success: false, error: 'Internal Server Error' });
|
| 90 |
-
}
|
| 91 |
-
});
|
| 92 |
-
|
| 93 |
-
app.listen(PORT, () => {
|
| 94 |
-
console.log(`π House of Ruqa Server running on port ${PORT}`);
|
| 95 |
-
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|