-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
59 lines (49 loc) · 1.53 KB
/
server.js
File metadata and controls
59 lines (49 loc) · 1.53 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
// Simple server for Vercel deployment
import express from 'express';
import path from 'path';
import fs from 'fs';
import { fileURLToPath } from 'url';
// Get __dirname equivalent in ES modules
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = express();
// Define the path to static files
const staticPath = path.join(__dirname, 'dist/public');
// Log for debugging
console.log('Server starting...');
console.log('__dirname:', __dirname);
console.log('staticPath:', staticPath);
console.log('staticPath exists:', fs.existsSync(staticPath));
// Serve static files
app.use(express.static(staticPath));
// API routes
app.get('/api/*', (req, res) => {
res.status(404).send('API routes are not available in this deployment');
});
// Serve favicon
app.get('/favicon.ico', (req, res) => {
const faviconPath = path.join(staticPath, 'favicon.ico');
if (fs.existsSync(faviconPath)) {
res.sendFile(faviconPath);
} else {
res.status(404).send('Favicon not found');
}
});
// Catch-all handler for SPA
app.get('*', (req, res) => {
const indexPath = path.join(staticPath, 'index.html');
if (fs.existsSync(indexPath)) {
res.sendFile(indexPath);
} else {
res.status(404).send('index.html not found');
}
});
// Vercel will use this export
export default app;
// For local testing, listen on a port if not running in Vercel
if (process.env.VERCEL !== '1') {
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});
}