Skip to content

Commit 5d8c8b1

Browse files
author
yggverse
committed
implement startup mode, init nex filesystem server
1 parent 1ec4b61 commit 5d8c8b1

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Based on [Ratchet](https://github.com/ratchetphp/Ratchet) asynchronous socket li
1111
* Multi-protocol:
1212
* [x] [NEX](https://nightfall.city/nex/info/specification.txt)
1313
* [ ] [Gemini](https://geminiprotocol.net)
14+
* Multi-mode:
15+
* [x] Static filesystem
16+
* [ ] Dynamic application
17+
* [ ] Reverse proxy
1418
* Connection event log
1519
* Optional:
1620
* file navigation on directory request
@@ -71,6 +75,8 @@ Provide arguments in `key=value` format, separated by space
7175

7276
###### Optional
7377

78+
* `mode` - server implementation variant, `fs` (filesystem) by default
79+
* `fs` - static files hosting for the `root` location
7480
* `host` - default is `127.0.0.1` e.g. `localhost` connections only
7581
* `port` - default value depends of server `type` selected, for example `1900` for `nex` or `1965` for `gemini`
7682
* `file` - index **file name** that server try to open on directory path requested, disabled by default

default.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"host":"127.0.0.1",
3+
"mode":"fs",
34
"list":true,
45
"dump":true
56
}

src/Controller/Nex.php renamed to src/Controller/Nex/Filesystem.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

3-
namespace Yggverse\Next\Controller;
3+
namespace Yggverse\Next\Controller\Nex;
44

55
use \Ratchet\MessageComponentInterface;
66

7-
class Nex implements MessageComponentInterface
7+
class Filesystem implements MessageComponentInterface
88
{
99
private \Yggverse\Next\Model\Environment $_environment;
1010
private \Yggverse\Next\Model\Filesystem $_filesystem;
@@ -43,7 +43,7 @@ public function __construct(
4343
(string) $this->_environment->get('port'),
4444
(string) $this->_filesystem->root()
4545
],
46-
_('[{time}] [init] server started at {host}:{port}{root}')
46+
_('[{time}] [init] filesystem server started at nex://{host}:{port}{root}')
4747
) . PHP_EOL
4848
);
4949
}

src/server.php

+22-4
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,26 @@
3131
{
3232
case 'nex':
3333

34+
switch ($environment->get('mode'))
35+
{
36+
case 'fs':
37+
38+
$controller = new \Yggverse\Next\Controller\Nex\Filesystem(
39+
$environment,
40+
$filesystem
41+
);
42+
43+
break;
44+
45+
default:
46+
47+
throw new \Exception(
48+
_('unsupported mode for nex server type!')
49+
);
50+
}
51+
3452
$server = \Ratchet\Server\IoServer::factory(
35-
new \Yggverse\Next\Controller\Nex(
36-
$environment,
37-
$filesystem
38-
),
53+
$controller,
3954
$environment->get('port'),
4055
$environment->get('host')
4156
);
@@ -56,4 +71,7 @@
5671
catch (\Exception $exception)
5772
{
5873
// @TODO
74+
print(
75+
$exception->getMessage()
76+
) . PHP_EOL;
5977
}

0 commit comments

Comments
 (0)