-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.php
45 lines (36 loc) · 1.67 KB
/
index.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
43
44
45
<?php
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/src/libs/Logger/index.php';
use React\Http\Middleware\RequestBodyBufferMiddleware;
use React\Http\Middleware\RequestBodyParserMiddleware;
use React\Http\Middleware\StreamingRequestMiddleware;
use Vertuoza\Libs\Logger\ApplicationLogger;
use Vertuoza\Libs\Logger\LogContext;
use function React\Promise\resolve;
use React\Http\Message\Response;
use React\Http\Message\ServerRequest;
use function Vertuoza\Libs\Logger\startLogger;
use GraphQL\Executor\Promise\Adapter\ReactPromiseAdapter;
use Vertuoza\Api\Graphql\Context\RequestContext;
use Vertuoza\Api\Graphql\GqlMiddlewares;
$logger = startLogger();
ini_set('memory_limit', $_ENV['MEMORY_LIMIT']);
try {
$graphQLPromiseAdapter = new ReactPromiseAdapter();
$dataLoaderPromiseAdapter = new \Overblog\PromiseAdapter\Adapter\ReactPromiseAdapter();
$http = new React\Http\HttpServer(
new StreamingRequestMiddleware(),
new RequestBodyBufferMiddleware(20 * 1024 * 1024),
new RequestBodyParserMiddleware(20 * 1024 * 1024, 1),
GqlMiddlewares::sandbox(),
RequestContext::middleware($dataLoaderPromiseAdapter),
GqlMiddlewares::schema($graphQLPromiseAdapter, $dataLoaderPromiseAdapter),
fn (ServerRequest $request) => resolve(new Response(404))
);
$socket = new React\Socket\SocketServer('0.0.0.0:' . $_ENV['PORT']);
$http->listen($socket);
ApplicationLogger::getInstance()->info("Server running on port " . $_ENV['PORT'] . PHP_EOL, new LogContext(null, null));
} catch (Throwable $e) {
ApplicationLogger::getInstance()->error($e, 'UNKNOWN_ERROR', new LogContext(null, null));
exit(0);
}