Skip to content

Commit

Permalink
cleanup, add apidocs endpoint, add nginx config for openapi domain
Browse files Browse the repository at this point in the history
  • Loading branch information
killua-eu committed Feb 25, 2024
1 parent bf40cea commit 91a5795
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 20 deletions.
13 changes: 13 additions & 0 deletions glued/Config/Nginx/sites-available/glued-core
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,16 @@ server {
include snippets/common/location-deny.conf;
}

server {
##########################
# Server setup #
##########################

include snippets/server/generated_openapi_name.conf;
root /var/www/html/glued-core/public/openapi-ui;
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
include snippets/common/location-deny.conf;
}

9 changes: 9 additions & 0 deletions glued/Config/routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,12 @@ routes:
provides: routes_list
methods:
get: Glued\Controllers\ServiceController:routes_list

be_core_apidocs_v1:
pattern: ${routes.be_core.path}/v1/apidocs
path: ${routes.be_core.path}/v1/apidocs
label: Openapi yamls/jsons
dscr: List URIs with Openapi source files
service: core
methods:
get: Glued\Controllers\ServiceController:apidocs
40 changes: 28 additions & 12 deletions glued/Controllers/ServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public function routes_list(Request $request, Response $response, array $args =

/**
* Returns an exception.
* @param Request $request
* @param Response $response
* @param array $args
* @param Request $request
* @param Response $response
* @param array $args
* @return Response Json result set.
*/
public function stub(Request $request, Response $response, array $args = []): Response {
Expand All @@ -36,20 +36,20 @@ public function stub(Request $request, Response $response, array $args = []): Re

/**
* Returns a health status response.
* @param Request $request
* @param Response $response
* @param array $args
* @param Request $request
* @param Response $response
* @param array $args
* @return Response Json result set.
*/
public function health(Request $request, Response $response, array $args = []): Response {
$params = $request->getQueryParams();
$data = [
'timestamp' => microtime(),
'status' => 'OK',
'params' => $params,
'service' => basename(__ROOT__),
'provided-for' => $_SERVER['HTTP_X-GLUED-AUTH-UUID'] ?? 'anonymous'
];
'timestamp' => microtime(),
'status' => 'OK',
'params' => $params,
'service' => basename(__ROOT__),
'provided-for' => $_SERVER['HTTP_X-GLUED-AUTH-UUID'] ?? 'anonymous'
];
//$data['x'] = $this->auth->verify_token()
if ($data['provided-for'] !== 'anonymous') { $this->auth->generate_api_token($_SERVER['HTTP_X-GLUED-AUTH-UUID']); }
return $response->withJson($data, options: JSON_UNESCAPED_SLASHES);
Expand All @@ -71,4 +71,20 @@ public function home(Request $request, Response $response, array $args = []): Re
return $response->withJson($data, options: JSON_UNESCAPED_SLASHES);
}

public function apidocs(Request $request, Response $response, array $args = []): Response {
$data = [];
$openapis = array_filter($this->settings['routes'], function ($route) {
return isset($route['provides']) && $route['provides'] === 'openapi';
});
foreach ($openapis as $route) {
$data[] = [
'url' => "{$this->settings['glued']['protocol']}{$this->settings['glued']['hostname']}{$route['path']}",
'name' => $route['label']
];
}
return $response->withJson($data, options: JSON_UNESCAPED_SLASHES);
}



}
8 changes: 0 additions & 8 deletions glued/middleware.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
<?php
/** @noinspection PhpUndefinedVariableInspection */
declare(strict_types=1);
use DI\Container;
use Glued\Lib\Middleware\AntiXSSMiddleware;
use Glued\Lib\Middleware\TimerMiddleware;
use Middlewares\Csp;
use Middlewares\TrailingSlash;
use Nyholm\Psr7\Response as Psr7Response;
use ParagonIE\CSPBuilder\CSPBuilder;
use Slim\App;
use Slim\Exception\HttpNotFoundException;
use Slim\Middleware\ErrorMiddleware;
use Slim\Middleware\MethodOverrideMiddleware;
use Tuupola\Middleware\CorsMiddleware;
use Zeuxisoo\Whoops\Slim\WhoopsMiddleware;
Expand Down

0 comments on commit 91a5795

Please sign in to comment.