-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathLitCalTestServer.php
42 lines (35 loc) · 1.28 KB
/
LitCalTestServer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once 'vendor/autoload.php';
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use LiturgicalCalendar\Api\Health;
use Dotenv\Dotenv;
$dotenv = Dotenv::createImmutable(__DIR__, ['.env', '.env.local', '.env.development', '.env.production'], false);
$dotenv->ifPresent(['API_PROTOCOL', 'API_HOST'])->notEmpty();
$dotenv->ifPresent(['API_PORT'])->isInteger();
$dotenv->ifPresent(['APP_ENV'])->notEmpty()->allowedValues(['development', 'production']);
$dotenv->ifPresent(['WS_PROTOCOL', 'WS_HOST'])->notEmpty();
$dotenv->ifPresent(['WS_PORT'])->isInteger();
$dotenv->safeLoad();
$API_PROTOCOL = $_ENV['API_PROTOCOL'] ?? 'https';
$API_HOST = $_ENV['API_HOST'] ?? 'litcal.johnromanodorazio.com';
$API_PORT = $_ENV['API_PORT'] ?? 443;
if (isset($_ENV['APP_ENV']) && $_ENV['APP_ENV'] === 'development') {
define('API_BASE_PATH', "{$API_PROTOCOL}://{$API_HOST}:{$API_PORT}");
} else {
$apiVersion = basename(__DIR__);
define('API_BASE_PATH', "{$API_PROTOCOL}://{$API_HOST}/api/{$apiVersion}");
}
$server = IoServer::factory(
new HttpServer(
new WsServer(
new Health()
)
),
$_ENV['WS_PORT'] ?? 8080
);
$server->run();