You've already forked LibreTranslate
							
							
				mirror of
				https://github.com/LibreTranslate/LibreTranslate.git
				synced 2025-10-30 23:37:48 +02:00 
			
		
		
		
	Add /health endpoint for service health checks
				
					
				
			Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
This commit is contained in:
		| @@ -520,6 +520,28 @@ def create_app(args): | ||||
|                          "targets": model2iso(language_pairs.get(l.code, [])) | ||||
|                         } for l in languages]) | ||||
|  | ||||
|     @bp.get("/health") | ||||
|     @limiter.exempt | ||||
|     def health(): | ||||
|         """ | ||||
|         Health Check | ||||
|         --- | ||||
|         tags: | ||||
|           - misc | ||||
|         responses: | ||||
|           200: | ||||
|             description: Service is healthy | ||||
|             schema: | ||||
|               id: health-response | ||||
|               type: object | ||||
|               properties: | ||||
|                 status: | ||||
|                   type: string | ||||
|                   description: Health status | ||||
|                   example: ok | ||||
|         """ | ||||
|         return jsonify({"status": "ok"}) | ||||
|  | ||||
|     # Add cors | ||||
|     @bp.after_request | ||||
|     def after_request(response): | ||||
|   | ||||
							
								
								
									
										11
									
								
								libretranslate/tests/test_api/test_api_health.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								libretranslate/tests/test_api/test_api_health.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| def test_api_get_health(client): | ||||
|     response = client.get("/health") | ||||
|  | ||||
|     assert response.status_code == 200 | ||||
|     assert response.json == {"status": "ok"} | ||||
|  | ||||
|  | ||||
| def test_api_health_must_fail_bad_request_type(client): | ||||
|     response = client.post("/health") | ||||
|  | ||||
|     assert response.status_code == 405 | ||||
		Reference in New Issue
	
	Block a user