27 lines
No EOL
665 B
JavaScript
27 lines
No EOL
665 B
JavaScript
const express = require('express');
|
|
const cors = require('cors');
|
|
const path = require('path');
|
|
const postsRoutes = require('./routes/posts');
|
|
const projectsRoutes = require('./routes/projects');
|
|
|
|
const app = express();
|
|
|
|
// Middleware
|
|
|
|
app.use(cors());
|
|
app.use(express.json());
|
|
|
|
// API Routes
|
|
app.use('/api/posts', postsRoutes);
|
|
app.use('/api/projects', projectsRoutes);
|
|
|
|
// Serve Static files in production
|
|
if (process.env.NODE_ENV === 'production') {
|
|
app.use(express.static(path.join(__dirname, '../client/dist')));
|
|
|
|
app.get('*', (req, res) => {
|
|
res.sendFile(path.resolve(__dirname, '../client', 'dist', 'index.html'));
|
|
});
|
|
}
|
|
|
|
module.exports = app; |