sync
;
This commit is contained in:
		
							parent
							
								
									3cd7496989
								
							
						
					
					
						commit
						fbe6f866d9
					
				
					 9 changed files with 933 additions and 19 deletions
				
			
		|  | @ -25,6 +25,7 @@ | |||
|         "js-yaml": "^4.1.0", | ||||
|         "loki-logger-ts": "^1.0.2", | ||||
|         "response-time": "^2.3.3", | ||||
|         "swagger-ui-express": "^5.0.1", | ||||
|         "uuid": "^11.1.0", | ||||
|         "winston": "^3.17.0", | ||||
|         "winston-loki": "^6.1.3" | ||||
|  | @ -34,6 +35,7 @@ | |||
|         "@types/express": "^5.0.0", | ||||
|         "@types/node": "^22.13.4", | ||||
|         "@types/response-time": "^2.3.8", | ||||
|         "@types/swagger-ui-express": "^4.1.8", | ||||
|         "globals": "^15.15.0", | ||||
|         "ts-node": "^10.9.2", | ||||
|         "tsx": "^4.19.3", | ||||
|  |  | |||
|  | @ -16,6 +16,8 @@ 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 swaggerMiddleware from "./swagger"; | ||||
| import swaggerUi from "swagger-ui-express"; | ||||
| 
 | ||||
| const logger: Logger = getLogger(); | ||||
| 
 | ||||
|  | @ -23,7 +25,6 @@ const app: Express = express(); | |||
| const port: string | number = getNumericEnvVar(EnvVars.Port); | ||||
| 
 | ||||
| app.use(express.json()); | ||||
| app.use(responseTime(responseTimeLogger)); | ||||
| 
 | ||||
| // TODO Replace with Express routes
 | ||||
| app.get('/', (_, res: Response) => { | ||||
|  | @ -33,17 +34,24 @@ app.get('/', (_, res: Response) => { | |||
|     }); | ||||
| }); | ||||
| 
 | ||||
| app.use('/student', studentRouter); | ||||
| app.use('/group', groupRouter); | ||||
| app.use('/assignment', assignmentRouter); | ||||
| app.use('/submission', submissionRouter); | ||||
| app.use('/class', classRouter); | ||||
| app.use('/question', questionRouter); | ||||
| app.use('/login', loginRouter); | ||||
| // Routes
 | ||||
| app.use('/student', studentRouter /* #swagger.tags = ['Student'] */); | ||||
| app.use('/group', groupRouter /* #swagger.tags = ['Group'] */); | ||||
| app.use('/assignment', assignmentRouter /* #swagger.tags = ['Assignment'] */); | ||||
| app.use('/submission', submissionRouter /* #swagger.tags = ['Submission'] */); | ||||
| app.use('/class', classRouter /* #swagger.tags = ['Class'] */); | ||||
| app.use('/question', questionRouter /* #swagger.tags = ['Question'] */); | ||||
| app.use('/login', loginRouter /* #swagger.tags = ['Login'] */); | ||||
| 
 | ||||
| app.use('/theme', themeRoutes); | ||||
| app.use('/learningPath', learningPathRoutes); | ||||
| app.use('/learningObject', learningObjectRoutes); | ||||
| app.use('/theme', themeRoutes /* #swagger.tags = ['Theme'] */); | ||||
| app.use('/learningPath', learningPathRoutes /* #swagger.tags = ['Learning Path'] */); | ||||
| app.use('/learningObject', learningObjectRoutes /* #swagger.tags = ['Learning Object'] */); | ||||
| 
 | ||||
| // Add response time loggin
 | ||||
| app.use(responseTime(responseTimeLogger)); | ||||
| 
 | ||||
| // Swagger UI for API documentation
 | ||||
| app.use('/api-docs', swaggerUi.serve, swaggerMiddleware); | ||||
| 
 | ||||
| async function startServer() { | ||||
|     await initORM(); | ||||
|  |  | |||
							
								
								
									
										11
									
								
								backend/src/swagger.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								backend/src/swagger.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,11 @@ | |||
| import { RequestHandler } from 'express'; | ||||
| import swaggerUi from 'swagger-ui-express'; | ||||
| import swaggerDocument from '../../docs/api/swagger.json'; | ||||
| 
 | ||||
| const swaggerOptions = { | ||||
|     explorer: true | ||||
| }; | ||||
| 
 | ||||
| const swaggerMiddleware: RequestHandler = swaggerUi.setup(swaggerDocument, swaggerOptions); | ||||
| 
 | ||||
| export default swaggerMiddleware; | ||||
|  | @ -3,6 +3,7 @@ | |||
|     "include": ["src/**/*.ts"], | ||||
|     "compilerOptions": { | ||||
|         "rootDir": "./src", | ||||
|         "outDir": "./dist" | ||||
|         "outDir": "./dist", | ||||
|         "resolveJsonModule": true | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Reference in a new issue