import express from 'express';
import { errorHandler } from './utils/error';
import routes from './api/routes';

const app = express();
const PORT = process.env.PORT || 3001;

// 简化的中间件
app.use(express.json({ limit: '10mb' }));
app.use(express.urlencoded({ extended: true, limit: '10mb' }));

// 路由
app.use('/api', routes);

// 错误处理
app.use(errorHandler);

// 启动服务器
app.listen(PORT, () => {
  console.log(`服务器运行在 http://localhost:${PORT}`);
});

export default app;