34 lines
825 B
JavaScript
34 lines
825 B
JavaScript
import express from 'express';
|
|
import cors from 'cors';
|
|
import videoRoutes from './routes/video.js';
|
|
|
|
const app = express();
|
|
const PORT = process.env.PORT || 3001;
|
|
|
|
// 中间件
|
|
app.use(cors());
|
|
app.use(express.json({ limit: '50mb' }));
|
|
app.use(express.urlencoded({ extended: true, limit: '50mb' }));
|
|
|
|
// 路由
|
|
app.use('/api/video', videoRoutes);
|
|
|
|
// 健康检查
|
|
app.get('/health', (req, res) => {
|
|
res.json({ status: 'ok', timestamp: new Date().toISOString() });
|
|
});
|
|
|
|
// 错误处理
|
|
app.use((err, req, res, next) => {
|
|
console.error('Server error:', err);
|
|
res.status(500).json({
|
|
error: 'Internal server error',
|
|
message: err.message
|
|
});
|
|
});
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`🚀 Server running on http://localhost:${PORT}`);
|
|
console.log(`📁 Video API: http://localhost:${PORT}/api/video`);
|
|
});
|