implement startup mode, init nex filesystem server

This commit is contained in:
yggverse 2024-05-06 20:43:08 +03:00
parent 1ec4b61970
commit 5d8c8b122b
4 changed files with 32 additions and 7 deletions

View File

@ -11,6 +11,10 @@ Based on [Ratchet](https://github.com/ratchetphp/Ratchet) asynchronous socket li
* Multi-protocol: * Multi-protocol:
* [x] [NEX](https://nightfall.city/nex/info/specification.txt) * [x] [NEX](https://nightfall.city/nex/info/specification.txt)
* [ ] [Gemini](https://geminiprotocol.net) * [ ] [Gemini](https://geminiprotocol.net)
* Multi-mode:
* [x] Static filesystem
* [ ] Dynamic application
* [ ] Reverse proxy
* Connection event log * Connection event log
* Optional: * Optional:
* file navigation on directory request * file navigation on directory request
@ -71,6 +75,8 @@ Provide arguments in `key=value` format, separated by space
###### Optional ###### Optional
* `mode` - server implementation variant, `fs` (filesystem) by default
* `fs` - static files hosting for the `root` location
* `host` - default is `127.0.0.1` e.g. `localhost` connections only * `host` - default is `127.0.0.1` e.g. `localhost` connections only
* `port` - default value depends of server `type` selected, for example `1900` for `nex` or `1965` for `gemini` * `port` - default value depends of server `type` selected, for example `1900` for `nex` or `1965` for `gemini`
* `file` - index **file name** that server try to open on directory path requested, disabled by default * `file` - index **file name** that server try to open on directory path requested, disabled by default

View File

@ -1,5 +1,6 @@
{ {
"host":"127.0.0.1", "host":"127.0.0.1",
"mode":"fs",
"list":true, "list":true,
"dump":true "dump":true
} }

View File

@ -1,10 +1,10 @@
<?php <?php
namespace Yggverse\Next\Controller; namespace Yggverse\Next\Controller\Nex;
use \Ratchet\MessageComponentInterface; use \Ratchet\MessageComponentInterface;
class Nex implements MessageComponentInterface class Filesystem implements MessageComponentInterface
{ {
private \Yggverse\Next\Model\Environment $_environment; private \Yggverse\Next\Model\Environment $_environment;
private \Yggverse\Next\Model\Filesystem $_filesystem; private \Yggverse\Next\Model\Filesystem $_filesystem;
@ -43,7 +43,7 @@ class Nex implements MessageComponentInterface
(string) $this->_environment->get('port'), (string) $this->_environment->get('port'),
(string) $this->_filesystem->root() (string) $this->_filesystem->root()
], ],
_('[{time}] [init] server started at {host}:{port}{root}') _('[{time}] [init] filesystem server started at nex://{host}:{port}{root}')
) . PHP_EOL ) . PHP_EOL
); );
} }

View File

@ -31,11 +31,26 @@ try
{ {
case 'nex': case 'nex':
switch ($environment->get('mode'))
{
case 'fs':
$controller = new \Yggverse\Next\Controller\Nex\Filesystem(
$environment,
$filesystem
);
break;
default:
throw new \Exception(
_('unsupported mode for nex server type!')
);
}
$server = \Ratchet\Server\IoServer::factory( $server = \Ratchet\Server\IoServer::factory(
new \Yggverse\Next\Controller\Nex( $controller,
$environment,
$filesystem
),
$environment->get('port'), $environment->get('port'),
$environment->get('host') $environment->get('host')
); );
@ -56,4 +71,7 @@ try
catch (\Exception $exception) catch (\Exception $exception)
{ {
// @TODO // @TODO
print(
$exception->getMessage()
) . PHP_EOL;
} }