Browse Source

implement startup mode, init nex filesystem server

main
yggverse 7 months ago
parent
commit
5d8c8b122b
  1. 6
      README.md
  2. 1
      default.json
  3. 6
      src/Controller/Nex/Filesystem.php
  4. 24
      src/server.php

6
README.md

@ -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

1
default.json

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

6
src/Controller/Nex.php → src/Controller/Nex/Filesystem.php

@ -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
); );
} }

24
src/server.php

@ -31,11 +31,26 @@ try
{ {
case 'nex': case 'nex':
$server = \Ratchet\Server\IoServer::factory( switch ($environment->get('mode'))
new \Yggverse\Next\Controller\Nex( {
case 'fs':
$controller = new \Yggverse\Next\Controller\Nex\Filesystem(
$environment, $environment,
$filesystem $filesystem
), );
break;
default:
throw new \Exception(
_('unsupported mode for nex server type!')
);
}
$server = \Ratchet\Server\IoServer::factory(
$controller,
$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;
} }

Loading…
Cancel
Save