-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
85 lines (65 loc) · 2.5 KB
/
server.js
File metadata and controls
85 lines (65 loc) · 2.5 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
import 'dotenv/config';
import express from 'express';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import fs from 'fs';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const app = express();
const PORT = process.env.PORT || 3000;
// Middleware
app.use(express.json({ limit: '10mb' }));
app.use(express.urlencoded({ extended: true, limit: '10mb' }));
// Logging middleware
app.use((req, res, next) => {
console.log(`${new Date().toISOString()} ${req.method} ${req.path}`);
next();
});
// Serve static files from public directory
app.use(express.static(join(__dirname, 'public')));
// Function to load and wrap Vercel API handlers
async function loadHandler(handlerPath) {
const handler = await import(handlerPath);
return handler.default;
}
// Wrapper to convert Vercel handler to Express middleware
function wrapVercelHandler(handlerPath) {
return async (req, res) => {
try {
const handler = await loadHandler(handlerPath);
await handler(req, res);
} catch (error) {
console.error('Handler error:', error);
if (!res.headersSent) {
res.status(500).json({ error: error.message });
}
}
};
}
// API Routes
app.post('/api/quick-add', wrapVercelHandler('./api/quick-add.js'));
app.get('/api/quick-add', wrapVercelHandler('./api/quick-add.js'));
app.post('/api/parse-screenshot', wrapVercelHandler('./api/parse-screenshot.js'));
app.post('/api/upload', wrapVercelHandler('./api/upload.js'));
app.get('/api/calendars', wrapVercelHandler('./api/calendars.js'));
app.post('/api/create-event', wrapVercelHandler('./api/create-event.js'));
app.post('/api/create-events', wrapVercelHandler('./api/create-events.js'));
app.get('/api/confirm-event', wrapVercelHandler('./api/confirm-event.js'));
app.get('/api/auth/google', wrapVercelHandler('./api/auth/google.js'));
app.get('/api/auth/callback', wrapVercelHandler('./api/auth/callback.js'));
app.post('/api/inbound-email', wrapVercelHandler('./api/inbound-email.js'));
// Health check endpoint
app.get('/health', (req, res) => {
res.json({ status: 'ok', timestamp: new Date().toISOString() });
});
// 404 handler
app.use((req, res) => {
res.status(404).json({ error: 'Not found' });
});
// Start server
app.listen(PORT, '0.0.0.0', () => {
console.log(`Screenshot Event Server running on port ${PORT}`);
console.log(`Local: http://localhost:${PORT}`);
console.log(`Tailscale: http://100.123.251.27:${PORT}`);
console.log(`mDNS: http://pi5.local:${PORT}`);
});