From 1c7e01f028a07c66c920daaffb71b10521cab53d Mon Sep 17 00:00:00 2001 From: yggverse Date: Sun, 5 May 2024 04:21:51 +0300 Subject: [PATCH] implement custom route settings --- config/example.json | 4 ++++ src/Controller/Server/Nex.php | 42 ++++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/config/example.json b/config/example.json index 42cb860..4b9ebed 100644 --- a/config/example.json +++ b/config/example.json @@ -11,6 +11,10 @@ { "host":"127.0.0.1", "port":1900, + "route": + { + "/test":"/path/to/page.gmi" + }, "event": { "init": diff --git a/src/Controller/Server/Nex.php b/src/Controller/Server/Nex.php index a982be9..1efcdb1 100644 --- a/src/Controller/Server/Nex.php +++ b/src/Controller/Server/Nex.php @@ -78,7 +78,7 @@ class Nex implements MessageComponentInterface // Route request switch (true) { - // Item + // Chanel item case (bool) preg_match('/\/(?\d+)($|\.gmi)$/i', $request, $attribute): $lines = []; @@ -145,7 +145,7 @@ class Nex implements MessageComponentInterface break; - // Chanel + // Channel page case (bool) preg_match('/^\/(?.+)$/i', $request, $attribute): $lines = []; @@ -207,23 +207,35 @@ class Nex implements MessageComponentInterface // Not found default: - $lines = []; - - // Get channels - foreach ((array) $this->_database->getChannels() as $channel) + // Try static route settings + if (isset($this->_config->route->{$request})) { - $lines[] = sprintf( - '=> /%s %s', - $channel->alias, - $channel->title + $response = file_get_contents( + $this->_config->route->{$request} ); } - // Build response - $response = implode( - PHP_EOL, - $lines - ); + // Build site map + else + { + $lines = []; + + // Get channels + foreach ((array) $this->_database->getChannels() as $channel) + { + $lines[] = sprintf( + '=> /%s %s', + $channel->alias, + $channel->title + ); + } + + // Build response + $response = implode( + PHP_EOL, + $lines + ); + } } // Debug message event on enabled