feat: add backend infrastructure - Express server, auth, CRUD APIs, DB migrations
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
58
server.js
Normal file
58
server.js
Normal file
@@ -0,0 +1,58 @@
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const helmet = require('helmet');
|
||||
const compression = require('compression');
|
||||
const path = require('path');
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3000;
|
||||
|
||||
// Security middleware
|
||||
app.use(helmet({ contentSecurityPolicy: false }));
|
||||
app.use(compression());
|
||||
app.use(cors({
|
||||
origin: process.env.FRONTEND_URL || true,
|
||||
credentials: true
|
||||
}));
|
||||
app.use(express.json({ limit: '10mb' }));
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
|
||||
// Database connection
|
||||
const { connectDB } = require('./src/db/connection');
|
||||
|
||||
// Routes
|
||||
const authRoutes = require('./src/routes/auth');
|
||||
const craftsmenRoutes = require('./src/routes/craftsmen');
|
||||
const productsRoutes = require('./src/routes/products');
|
||||
const ordersRoutes = require('./src/routes/orders');
|
||||
|
||||
app.use('/api/auth', authRoutes);
|
||||
app.use('/api/craftsmen', craftsmenRoutes);
|
||||
app.use('/api/products', productsRoutes);
|
||||
app.use('/api/orders', ordersRoutes);
|
||||
|
||||
// Health check
|
||||
app.get('/api/health', (req, res) => {
|
||||
res.json({ status: 'ok', service: 'shokuninmarche-api', timestamp: new Date().toISOString() });
|
||||
});
|
||||
|
||||
// Serve React frontend in production
|
||||
app.use(express.static(path.join(__dirname, 'client/dist')));
|
||||
app.get('*', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, 'client/dist', 'index.html'));
|
||||
});
|
||||
|
||||
// Start server
|
||||
async function start() {
|
||||
try {
|
||||
await connectDB();
|
||||
app.listen(PORT, () => {
|
||||
console.log(`🚀 shokuninmarche server running on port ${PORT}`);
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Failed to start server:', err);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
start();
|
||||
Reference in New Issue
Block a user