refactor(backend): Gebruik /api router
This commit is contained in:
		
							parent
							
								
									4c5f6196f6
								
							
						
					
					
						commit
						c9e95f4429
					
				
					 2 changed files with 38 additions and 30 deletions
				
			
		|  | @ -1,23 +1,13 @@ | |||
| import express, { Express, Response } from 'express'; | ||||
| import express, { Express } from 'express'; | ||||
| import { initORM } from './orm.js'; | ||||
| 
 | ||||
| import themeRoutes from './routes/themes.js'; | ||||
| import learningPathRoutes from './routes/learning-paths.js'; | ||||
| import learningObjectRoutes from './routes/learning-objects.js'; | ||||
| 
 | ||||
| import studentRouter from './routes/student.js'; | ||||
| import groupRouter from './routes/group.js'; | ||||
| import assignmentRouter from './routes/assignment.js'; | ||||
| import submissionRouter from './routes/submission.js'; | ||||
| import classRouter from './routes/class.js'; | ||||
| import questionRouter from './routes/question.js'; | ||||
| import authRouter from './routes/auth.js'; | ||||
| import { authenticateUser } from './middleware/auth/auth.js'; | ||||
| import cors from './middleware/cors.js'; | ||||
| import { getLogger, Logger } from './logging/initalize.js'; | ||||
| import { responseTimeLogger } from './logging/responseTimeLogger.js'; | ||||
| import responseTime from 'response-time'; | ||||
| import { EnvVars, getNumericEnvVar } from './util/envvars.js'; | ||||
| import apiRouter from './routes/router.js'; | ||||
| 
 | ||||
| const logger: Logger = getLogger(); | ||||
| 
 | ||||
|  | @ -29,24 +19,7 @@ app.use(express.json()); | |||
| app.use(responseTime(responseTimeLogger)); | ||||
| app.use(authenticateUser); | ||||
| 
 | ||||
| // TODO Replace with Express routes
 | ||||
| app.get('/api/', (_, res: Response) => { | ||||
|     logger.debug('GET /api/'); | ||||
|     res.json({ | ||||
|         message: 'Hello Dwengo!🚀', | ||||
|     }); | ||||
| }); | ||||
| 
 | ||||
| app.use('/api/student', studentRouter); | ||||
| app.use('/api/group', groupRouter); | ||||
| app.use('/api/assignment', assignmentRouter); | ||||
| app.use('/api/submission', submissionRouter); | ||||
| app.use('/api/class', classRouter); | ||||
| app.use('/api/question', questionRouter); | ||||
| app.use('/api/auth', authRouter); | ||||
| app.use('/api/theme', themeRoutes); | ||||
| app.use('/api/learningPath', learningPathRoutes); | ||||
| app.use('/api/learningObject', learningObjectRoutes); | ||||
| app.get('/api', apiRouter); | ||||
| 
 | ||||
| async function startServer() { | ||||
|     await initORM(); | ||||
|  |  | |||
							
								
								
									
										35
									
								
								backend/src/routes/router.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								backend/src/routes/router.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,35 @@ | |||
| import { Response, Router } from 'express'; | ||||
| import studentRouter from './student'; | ||||
| import groupRouter from './group'; | ||||
| import assignmentRouter from './assignment'; | ||||
| import submissionRouter from './submission'; | ||||
| import classRouter from './class'; | ||||
| import questionRouter from './question'; | ||||
| import authRouter from './auth'; | ||||
| import themeRoutes from './themes'; | ||||
| import learningPathRoutes from './learning-paths'; | ||||
| import learningObjectRoutes from './learning-objects'; | ||||
| import { getLogger, Logger } from '../logging/initalize'; | ||||
| 
 | ||||
| const router = Router(); | ||||
| const logger: Logger = getLogger(); | ||||
| 
 | ||||
| router.get('/', (_, res: Response) => { | ||||
|     logger.debug('GET /'); | ||||
|     res.json({ | ||||
|         message: 'Hello Dwengo!🚀', | ||||
|     }); | ||||
| }); | ||||
| 
 | ||||
| router.use('/student', studentRouter); | ||||
| router.use('/group', groupRouter); | ||||
| router.use('/assignment', assignmentRouter); | ||||
| router.use('/submission', submissionRouter); | ||||
| router.use('/class', classRouter); | ||||
| router.use('/question', questionRouter); | ||||
| router.use('/auth', authRouter); | ||||
| router.use('/theme', themeRoutes); | ||||
| router.use('/learningPath', learningPathRoutes); | ||||
| router.use('/learningObject', learningObjectRoutes); | ||||
| 
 | ||||
| export default router; | ||||
		Reference in a new issue