-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
62 lines (52 loc) · 1.49 KB
/
Copy pathapp.js
File metadata and controls
62 lines (52 loc) · 1.49 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
// ============================================
// FILE: app.js - UPDATED WITH MCP ROUTES
// ============================================
const express = require('express');
const webhookRoutes = require('./routes/webhookRoutes');
const mcpRoutes = require('./routes/mcpRoutes');
const errorHandler = require('./middleware/errorHandler');
const Logger = require('./utils/logger');
const app = express();
// Middleware
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// Request logging
app.use((req, res, next) => {
Logger.debug(`${req.method} ${req.path}`, {
query: req.query,
body: req.body
});
next();
});
// ============================================
// ROUTES
// ============================================
// Webhook routes (existing)
app.use(process.env.BASE_ROUTE || '/webhook', webhookRoutes);
// MCP Service routes (new - for separate MCP server)
app.use('/mcp', mcpRoutes);
// Root endpoint
app.get('/', (req, res) => {
res.json({
service: 'WhatsApp Webhook Service',
status: 'running',
version: '1.0.0',
endpoints: {
webhook: `POST ${process.env.BASE_ROUTE || "Not set"}`,
mcp: 'POST /mcp/:toolName',
health: 'GET /webhook/health'
}
});
});
// Health check for bot
app.get('/health', (req, res) => {
res.json({
status: 'ok',
service: 'whatsapp-bot',
timestamp: new Date().toISOString(),
uptime: process.uptime()
});
});
// Error handler (must be last)
app.use(errorHandler);
module.exports = app;