Skip to content

Commit

Permalink
support cops_full_url in rest api - see #74
Browse files Browse the repository at this point in the history
  • Loading branch information
mikespub committed Feb 26, 2024
1 parent 7a113bf commit c117955
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/Output/RestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function getOutput($result = null)
$path = $this->getPathInfo();
$params = $this->matchPathInfo($path);
if (!isset($params)) {
header('Location: ' . $this->request->script() . '/index');
header('Location: ' . Route::url(static::$endpoint) . '/index');
exit;
}
if ($this->isExtra) {
Expand Down Expand Up @@ -281,7 +281,7 @@ public static function getTable($database, $name, $request)
public static function getOpenApi($request)
{
$result = ["openapi" => "3.0.3", "info" => ["title" => "COPS REST API", "version" => Config::VERSION]];
$result["servers"] = [["url" => $request->script(), "description" => "COPS REST API Endpoint"]];
$result["servers"] = [["url" => Route::url(static::$endpoint), "description" => "COPS REST API Endpoint"]];
$result["components"] = ["securitySchemes" => ["ApiKeyAuth" => ["type" => "apiKey", "in" => "header", "name" => "X-API-KEY"]]];
$result["paths"] = [];
foreach (Route::getRoutes() as $route => $queryParams) {
Expand Down
3 changes: 2 additions & 1 deletion restapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use SebLucas\Cops\Input\Config;
use SebLucas\Cops\Input\Request;
use SebLucas\Cops\Input\Route;
use SebLucas\Cops\Output\Format;
use SebLucas\Cops\Output\RestApi;

Expand All @@ -28,7 +29,7 @@
if (empty($path)) {
header('Content-Type:text/html;charset=utf-8');

$data = ['link' => $request->script() . '/openapi'];
$data = ['link' => Route::url(Config::ENDPOINT["restapi"]) . '/openapi'];
$template = __DIR__ . '/templates/restapi.html';
echo Format::template($data, $template);
return;
Expand Down

0 comments on commit c117955

Please sign in to comment.