Added status checker endpoint for Shields.io

Added status checker endpoint for Shields.io under "status.php"

Added router.php and reference in server.conf

Removed ping.php
This commit is contained in:
Victor Westerlund 2021-02-08 12:38:13 +01:00
parent 70369f8163
commit b15983ceae
4 changed files with 34 additions and 7 deletions

2
.gitignore vendored
View file

@ -1,4 +1,4 @@
.well-known/
api/endpoint/*
!api/endpoint/ping.php
!api/endpoint/status.php

View file

@ -1,3 +0,0 @@
<?php
echo "Pong";

32
api/endpoint/status.php Normal file
View file

@ -0,0 +1,32 @@
<?php
header("Content-Type: application/json");
$api = $_GET["api"];
function response($online = false) {
$isError = $online ? true : false;
$message = $online ? "Online" : "Offline";
$color = $online ? "green" : "lightgrey";
$response = [
"schemaVersion" => 1,
"label" => "API",
"message" => $message,
"color" => $color,
"isError" => $isError
];
echo json_encode($response);
}
function getStatus() {
if(!is_dir($api)) {
response(false);
return false;
}
response(true);
}
getStatus();

View file

@ -59,15 +59,13 @@ server {
root /var/www/victorwesterlund.com/api/endpoint;
index router.php;
location / {
try_files $uri $uri.html $uri/ @extensionless-php;
index index.html index.htm index.php;
}
location ~ \.php$ {
try_files $uri $uri/ =404;
try_files $uri $uri/ /router.php =404;
add_header Access-Control-Allow-Origin *;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;