This repository was archived by the owner on Sep 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
148 lines (134 loc) Β· 3.61 KB
/
Copy pathserver.js
File metadata and controls
148 lines (134 loc) Β· 3.61 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const path = require('path');
const app = express();
const PORT = process.env.PORT || 3001;
/* --------------------------- Middleware --------------------------- */
app.use(
cors({
origin: '*',
credentials: true,
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization'],
})
);
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
/* ------ Serve static files + Root route -> public/index.html ------ */
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
/* ------------------------------ Health ---------------------------- */
app.get('/health', (req, res) => {
res.json({
status: 'ok',
timestamp: new Date().toISOString(),
message: 'Realtalk AI Backend is healthy!',
});
});
/* --------------------------- Dashboard API ------------------------ */
app.get('/api/dashboard/stats', (req, res) => {
res.json({
users: 2453,
revenue: 48275,
orders: 846,
projects: 142,
userChange: 12,
revenueChange: 23,
orderChange: -5,
projectChange: 8,
});
});
app.get('/api/dashboard/activity', (req, res) => {
res.json([
{
id: 1,
type: 'user',
title: 'New user registered',
description: 'Sarah Johnson joined the platform',
time: '2m ago',
icon: 'π€',
},
{
id: 2,
type: 'payment',
title: 'Payment received',
description: 'Invoice #1847 has been paid',
time: '1h ago',
icon: 'β
',
},
{
id: 3,
type: 'alert',
title: 'Server warning',
description: 'CPU usage exceeded 80%',
time: '3h ago',
icon: 'β οΈ',
},
{
id: 4,
type: 'comment',
title: 'New comment',
description: 'Mike posted on Project Alpha',
time: '5h ago',
icon: 'π¬',
},
]);
});
app.get('/api/dashboard/chart', (req, res) => {
res.json({
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul'],
values: [8500, 10200, 7800, 12400, 9600, 13100, 8900],
});
});
app.get('/api/dashboard/customers', (req, res) => {
res.json([
{
id: 1,
name: 'Alice Smith',
email: 'alice@example.com',
status: 'active',
revenue: 3428,
created: 'Jan 12, 2025',
},
{
id: 2,
name: 'Bob Johnson',
email: 'bob@example.com',
status: 'pending',
revenue: 1892,
created: 'Jan 10, 2025',
},
]);
});
/* --------------------------- Retell Route ------------------------- */
// Add this line with your other routes
app.use('/api/retell', require('./routes/retell'));
/* ----------------------- 404 + Error Handling --------------------- */
app.use((req, res) => {
res.status(404).json({
message: `Cannot ${req.method} ${req.path}`,
error: 'Not Found',
statusCode: 404,
});
});
app.use((err, req, res, _next) => {
console.error('Unhandled Error:', err);
res.status(500).json({
error: 'Internal Server Error',
message: process.env.NODE_ENV === 'development' ? err.message : undefined,
});
});
/* ----------------------------- Start ------------------------------ */
app.listen(PORT, () => {
console.log(`
π Server running at: http://localhost:${PORT}
π Dashboard: http://localhost:${PORT}
π₯ Health: http://localhost:${PORT}/health
π Stats API: http://localhost:${PORT}/api/dashboard/stats
π Retell API: http://localhost:${PORT}/api/retell
`);
});
module.exports = app;