mirror of
https://github.com/acedanger/finance.git
synced 2025-12-05 22:50:12 -08:00
transitioned from astro to react
This commit is contained in:
39
server/index.ts
Normal file
39
server/index.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { dirname, join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import cors from 'cors';
|
||||
import { config } from 'dotenv';
|
||||
import express from 'express';
|
||||
|
||||
// Load environment variables
|
||||
config();
|
||||
|
||||
// Import API routes
|
||||
import accountsRouter from './routes/accounts.js';
|
||||
import transactionsRouter from './routes/transactions.js';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3001;
|
||||
|
||||
// Middleware
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
// API routes
|
||||
app.use('/api/accounts', accountsRouter);
|
||||
app.use('/api/transactions', transactionsRouter);
|
||||
|
||||
// Serve static files in production
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
app.use(express.static(join(__dirname, '../client')));
|
||||
|
||||
app.get('*', (req, res) => {
|
||||
res.sendFile(join(__dirname, '../client/index.html'));
|
||||
});
|
||||
}
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Server running on port ${PORT}`);
|
||||
});
|
||||
Reference in New Issue
Block a user