Working Database setupgit add .
This commit is contained in:
75
src/index.ts
Normal file
75
src/index.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import express from 'express';
|
||||
import cors from 'cors';
|
||||
import { disconnectDB } from './db';
|
||||
import { startSyncScheduler, stopSyncScheduler } from './jobs/sync-scheduler';
|
||||
|
||||
// Import routes
|
||||
import usersRoutes from './routes/users.routes';
|
||||
import gradesRoutes from './routes/grades.routes';
|
||||
import statsRoutes from './routes/stats.routes';
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 4000;
|
||||
|
||||
// Middleware
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
// Health check
|
||||
app.get('/health', (req, res) => {
|
||||
res.json({
|
||||
status: 'ok',
|
||||
message: 'Skyward Backend API is running',
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
});
|
||||
|
||||
// Routes
|
||||
app.use('/api/users', usersRoutes);
|
||||
app.use('/api', gradesRoutes);
|
||||
app.use('/api/stats', statsRoutes);
|
||||
|
||||
// 404 handler
|
||||
app.use((req, res) => {
|
||||
res.status(404).json({
|
||||
success: false,
|
||||
error: 'Route not found',
|
||||
});
|
||||
});
|
||||
|
||||
// Start server
|
||||
app.listen(PORT, () => {
|
||||
console.log(`\n🚀 Skyward Backend API running on port ${PORT}`);
|
||||
console.log(`📡 Health check: http://localhost:${PORT}/health\n`);
|
||||
|
||||
console.log('Available endpoints:');
|
||||
console.log(' POST /api/users/register');
|
||||
console.log(' GET /api/users');
|
||||
console.log(' DELETE /api/users/:username');
|
||||
console.log(' GET /api/users/:username/grades');
|
||||
console.log(' GET /api/users/:username/classes');
|
||||
console.log(' GET /api/users/:username/classes/:category/assignments');
|
||||
console.log(' GET /api/users/:username/history');
|
||||
console.log(' POST /api/sync/manual');
|
||||
console.log(' GET /api/stats/overall');
|
||||
console.log(' GET /api/stats/users/:username');
|
||||
console.log(' GET /api/stats/users/:username/classes/:category\n');
|
||||
|
||||
// Start background sync scheduler
|
||||
startSyncScheduler();
|
||||
});
|
||||
|
||||
// Graceful shutdown
|
||||
process.on('SIGINT', async () => {
|
||||
console.log('\n\n[Server] Shutting down gracefully...');
|
||||
stopSyncScheduler();
|
||||
await disconnectDB();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
process.on('SIGTERM', async () => {
|
||||
console.log('\n\n[Server] Shutting down gracefully...');
|
||||
stopSyncScheduler();
|
||||
await disconnectDB();
|
||||
process.exit(0);
|
||||
});
|
||||
Reference in New Issue
Block a user