-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
91 lines (77 loc) · 2.72 KB
/
server.js
File metadata and controls
91 lines (77 loc) · 2.72 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
// Simple entry point for Vercel deployment - No TypeScript required
// Triggering fresh commit for Vercel
const express = require('express');
const cors = require('cors');
const helmet = require('helmet');
const dotenv = require('dotenv');
// Load environment variables
dotenv.config();
const app = express();
// Middleware
app.use(helmet());
app.use(cors());
app.use(express.json());
// Health check endpoint
app.get('/health', (req, res) => {
res.status(200).json({
status: 'healthy',
deployment: 'vercel',
environment: process.env.NODE_ENV,
timestamp: new Date().toISOString()
});
});
// SharpSpring webhook endpoint - Basic implementation
app.post('/webhooks/sharpspring', (req, res) => {
try {
// Log the webhook payload
console.log('Received SharpSpring webhook:', JSON.stringify(req.body, null, 2));
// Respond immediately to acknowledge receipt
res.status(200).json({ status: 'success', message: 'Webhook received' });
// Process would happen asynchronously in the full implementation
} catch (error) {
console.error('Error handling webhook:', error);
res.status(500).json({ error: 'Internal server error' });
}
});
// Interaction logging endpoint - Basic implementation
app.post('/api/log-interaction', (req, res) => {
try {
const { leadIdentifier, identifierType, interactionType, summary } = req.body;
// Basic validation
if (!leadIdentifier || !identifierType || !interactionType || !summary) {
return res.status(400).json({
message: 'Missing required fields: leadIdentifier, identifierType, interactionType, summary'
});
}
// Log the interaction request
console.log('Received interaction logging request:', {
leadIdentifier,
identifierType,
interactionType,
summary
});
// Return success (would actually process in the full implementation)
res.status(200).json({
message: 'Interaction logged successfully (stub implementation)',
leadId: 'sample-id',
newScore: 50
});
} catch (error) {
console.error('Error processing interaction:', error);
res.status(500).json({ message: 'Internal server error' });
}
});
// Fallback route
app.get('*', (req, res) => {
res.status(200).send('SharpSpring API Server is running. Check documentation for available endpoints.');
});
// Start server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
console.log('Available endpoints:');
console.log('- GET /health - Health check');
console.log('- POST /webhooks/sharpspring - SharpSpring webhook endpoint');
console.log('- POST /api/log-interaction - Log user interactions with leads');
});
module.exports = app;