Files
Final-Year-Project/Backend/index.ts

42 lines
993 B
TypeScript

import express from 'express';
import { toNodeHandler } from 'better-auth/node';
import { auth } from './auth';
import videosRoutes from './routes/videos';
import adminRoutes from './routes/admin';
import { ensureMinioBucket } from './utils/minio';
const app = express();
app.get('/', (_req, res) => {
res.send('API is running');
});
app.all('/api/auth/*splat', toNodeHandler(auth));
app.use(express.json());
app.use('/videos', videosRoutes);
app.use('/admin', adminRoutes);
app.use((err: unknown, _req: express.Request, res: express.Response, _next: express.NextFunction) => {
console.error(err);
res.status(500).json({ message: 'Internal server error' });
});
const port = Number(process.env.PORT ?? 3000);
const start = async () => {
try {
await ensureMinioBucket();
} catch (error) {
console.error('MinIO initialization failed', error);
process.exit(1);
}
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
};
start();