-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
60 lines (51 loc) · 1.69 KB
/
Copy pathserver.js
File metadata and controls
60 lines (51 loc) · 1.69 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
import express from 'express';
import path from 'path';
import { createServer as createViteServer } from 'vite';
import { connectDB } from './server/db.js';
import authRoutes from './server/routes/authRoutes.js';
import transactionRoutes from './server/routes/transactionRoutes.js';
import reportRoutes from './server/routes/reportRoutes.js';
import supportRoutes from './server/routes/supportRoutes.js';
import adminRoutes from './server/routes/adminRoutes.js';
async function startServer() {
const app = express();
const PORT = 3000;
// Initialize MongoDB connection & seeding
await connectDB();
// JSON middleware
app.use(express.json());
// Health check
app.get('/api/health', (_req, res) => {
res.json({
status: 'ok',
app: 'Zen FinTrack',
database: 'MongoDB',
tagline: 'Simple tracking. Smarter saving.',
timestamp: new Date().toISOString(),
});
});
// API Routes
app.use('/api/auth', authRoutes);
app.use('/api/transactions', transactionRoutes);
app.use('/api/reports', reportRoutes);
app.use('/api/support', supportRoutes);
app.use('/api/admin', adminRoutes);
// Vite middleware for dev or static server in prod
if (process.env.NODE_ENV !== 'production') {
const vite = await createViteServer({
server: { middlewareMode: true },
appType: 'spa',
});
app.use(vite.middlewares);
} else {
const distPath = path.join(process.cwd(), 'dist');
app.use(express.static(distPath));
app.get('*', (_req, res) => {
res.sendFile(path.join(distPath, 'index.html'));
});
}
app.listen(PORT, '0.0.0.0', () => {
console.log(`Zen FinTrack server listening on http://0.0.0.0:${PORT}`);
});
}
startServer();