import express from 'express';
import cors from 'cors';
import apiRoutes from './routes';
import mcpRoutes from './mcp';
const app = express();
const port = process.env.PORT || 3000;
// Middleware
app.use(cors());
app.use(express.json());
// Request logging
app.use((req, res, next) => {
console.log(`${new Date().toISOString()} ${req.method} ${req.path}`);
next();
});
// API Routes
app.use('/api', apiRoutes);
app.use('/api', mcpRoutes);
// Root endpoint
app.get('/', (req, res) => {
res.json({
service: 'APIM MCP Backend API',
version: '1.0.0',
endpoints: {
health: '/api/health',
products: '/api/products',
orders: '/api/orders',
mcp: '/api/mcp'
}
});
});
// Error handler
app.use((err: Error, req: express.Request, res: express.Response, next: express.NextFunction) => {
console.error('Error:', err);
res.status(500).json({ error: 'Internal server error' });
});
app.listen(port, () => {
console.log(`Server running on port ${port}`);
console.log(`Health: http://localhost:${port}/api/health`);
console.log(`MCP: http://localhost:${port}/api/mcp`);
});