mercureact/bin/mercureactd

74 lines
1.8 KiB
Plaintext
Raw Normal View History

2024-03-10 02:06:19 +00:00
#!/usr/bin/env php
<?php
use NoccyLabs\Mercureact\Configuration;
use NoccyLabs\Mercureact\Daemon;
2024-03-11 22:20:48 +00:00
use PHPUnit\TextUI\Help;
2024-03-10 02:06:19 +00:00
require_once __DIR__."/../vendor/autoload.php";
2024-03-11 22:20:48 +00:00
$opts = getopt("c:C:h");
if (isset($opts['h'])) {
fwrite(STDERR, <<<HELP
Mercureact Realtime SSE Daemon
(c) 2024, NoccyLabs - Distributed under GNU GPL v3 or later.
Options:
-c config Read configuration from file
-C config Write a new configuration to file and open with editor
HELP);
exit(0);
}
if (isset($opts['C'])) {
$file = $opts['C'];
if (file_exists($file)) {
fwrite(STDERR, "File {$file} already exists. Will not overwrite.\n");
exit(1);
}
file_put_contents($file, <<<DEFAULTS
server:
public_url: https://example.com
address: 0.0.0.0:9000
2024-03-11 22:20:48 +00:00
cors:
allow_origin: '*'
csp: "default-src * 'self' http: 'unsafe-eval' 'unsafe-inline'; connect-src * 'self'"
encryption:
cert: foo.pem
key: foo.key
websocket:
enable: true
publish:
overwrite_id: false
reject_duplicates: true
subscribe:
allow_anonymous: true
security:
jwt_secret: "!ChangeThisMercureHubJWTSecretKey!"
DEFAULTS);
passthru("editor ".escapeshellarg($file));
exit(1);
}
2024-03-11 01:15:04 +00:00
if (isset($opts['c'])) {
$config = Configuration::fromFile($opts['c']);
} else {
$config = Configuration::createDefault()
->setListenAddress('127.0.0.1:8888')
->setAllowOriginHeader("*")
->setContentSecurityPolicyHeader("default-src * 'self' http: 'unsafe-eval' 'unsafe-inline'; connect-src * 'self'")
2024-03-11 01:15:04 +00:00
->setAllowAnonymousSubscribe(true)
->setJwtSecret("!ChangeThisMercureHubJWTSecretKey!");
}
2024-03-10 02:06:19 +00:00
$daemon = new Daemon($config);
$daemon->start();