-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathserver.js
More file actions
122 lines (106 loc) · 3.79 KB
/
server.js
File metadata and controls
122 lines (106 loc) · 3.79 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
const express = require('express');
const path = require('path');
const cors = require('cors');
require('dotenv').config();
const app = express();
const PORT = process.env.PORT || 3000;
// Increase header size limits
app.use(express.json({ limit: '50mb' }));
app.use(express.urlencoded({ limit: '50mb', extended: true }));
// Middleware
app.use(cors());
// Serve static files from build directory
app.use(express.static(path.join(__dirname, 'build')));
// API Routes - Handle ES6 modules properly
app.post('/api/analyze-personality', async (req, res) => {
try {
console.log('API request received:', {
method: req.method,
url: req.url,
headers: Object.keys(req.headers),
bodySize: JSON.stringify(req.body).length
});
const { default: handler } = await import('./api/analyze-personality.js');
await handler(req, res);
} catch (error) {
console.error('Error loading analyze-personality handler:', error);
if (!res.headersSent) {
res.status(500).json({ error: 'Internal server error' });
}
}
});
app.get('/api/tinymce-config', async (req, res) => {
try {
const { default: handler } = await import('./api/tinymce-config.js');
await handler(req, res);
} catch (error) {
console.error('Error loading tinymce-config handler:', error);
res.status(500).json({ error: 'Internal server error' });
}
});
// Public API routes
app.get('/api/posts', async (req, res) => {
try {
const { default: handler } = await import('./api/posts.js');
await handler(req, res);
} catch (error) {
console.error('Error loading posts handler:', error);
res.status(500).json({ error: 'Internal server error' });
}
});
app.get('/api/events', async (req, res) => {
try {
const { default: handler } = await import('./api/events.js');
await handler(req, res);
} catch (error) {
console.error('Error loading events handler:', error);
res.status(500).json({ error: 'Internal server error' });
}
});
// Check for admin API routes
app.all('/api/admin/supabase-admin', async (req, res) => {
try {
const { default: handler } = await import('./api/admin/supabase-admin.js');
await handler(req, res);
} catch (error) {
console.error('Error loading admin handler:', error);
res.status(500).json({ error: 'Admin API not available' });
}
});
// Settings API
app.all('/api/settings', async (req, res) => {
try {
const { default: handler } = await import('./api/settings.js');
await handler(req, res);
} catch (error) {
console.error('Error loading settings handler:', error);
res.status(500).json({ error: 'Settings API not available' });
}
});
// Registrations API
app.all('/api/registrations', async (req, res) => {
try {
const { default: handler } = await import('./api/registrations.js');
await handler(req, res);
} catch (error) {
console.error('Error loading registrations handler:', error);
res.status(500).json({ error: 'Registrations API not available' });
}
});
// Serve React app for all other routes
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
// Error handling middleware
app.use((err, req, res, next) => {
console.error('Server error:', err);
res.status(500).json({ error: 'Internal server error' });
});
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
console.log(`React app: http://localhost:${PORT}`);
console.log(`API endpoints:`);
console.log(` POST http://localhost:${PORT}/api/analyze-personality`);
console.log(` GET http://localhost:${PORT}/api/tinymce-config`);
});
module.exports = app;