Update simple-status.php
This commit is contained in:
		
							parent
							
								
									39565f5ae1
								
							
						
					
					
						commit
						c140107114
					
				|  | @ -1,22 +1,26 @@ | |||
| <?php | ||||
| /* | ||||
| Plugin Name: Simple Status | ||||
| Description: Provides a custom endpoint for health checks. | ||||
| Description: Adds a custom health check endpoint for monitoring. | ||||
| Version: 1.0 | ||||
| Author: Colin | ||||
| Author: Your Name | ||||
| */ | ||||
| 
 | ||||
| function simple_status_endpoint() { | ||||
|     // Perform any necessary checks here
 | ||||
|     $status = array('status' => 'ok'); | ||||
|     wp_send_json($status); | ||||
| } | ||||
| 
 | ||||
| // Register the custom endpoint
 | ||||
| // Add a simple health check endpoint in your custom plugin
 | ||||
| add_action('rest_api_init', function () { | ||||
|     register_rest_route('simple/v1', '/status', array( | ||||
|     error_log('Initializing custom health check route.'); | ||||
|     register_rest_route('custom/v1', '/health', array( | ||||
|         'methods' => 'GET', | ||||
|         'callback' => 'simple_status_endpoint', | ||||
|         'callback' => 'custom_health_check', | ||||
|     )); | ||||
| }); | ||||
| ?>
 | ||||
| 
 | ||||
| function custom_health_check() { | ||||
|     error_log('Health check endpoint hit.'); | ||||
|     // Perform basic checks here (e.g., database connectivity)
 | ||||
|     if (is_wp_error($response = wp_remote_get(home_url()))) { | ||||
|         return new WP_Error('site_down', 'Site is down', array('status' => 500)); | ||||
|     } | ||||
| 
 | ||||
|     return new WP_REST_Response(array('status' => 'UP'), 200); | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue