This commit is contained in:
2025-04-25 22:27:47 -04:00
parent ac99a78bdf
commit d5167074a0
17 changed files with 173 additions and 30 deletions

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Siteworxpro\App\Facades;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Support\Facades\Facade;
use Siteworx\Config\Exception\EmptyDirectoryException;
use Siteworx\Config\Exception\FileNotFoundException;
@@ -21,6 +22,10 @@ use Siteworx\Config\Exception\UnsupportedFormatException;
*/
class Config extends Facade
{
protected static $cached = false;
/**
* @throws UnsupportedFormatException
* @throws FileNotFoundException
@@ -28,6 +33,17 @@ class Config extends Facade
*/
public static function getFacadeRoot(): \Siteworx\Config\Config
{
if (self::$resolvedInstance !== null) {
try {
$config = self::resolveFacadeInstance(self::getFacadeAccessor());
if ($config instanceof \Siteworx\Config\Config) {
return $config;
}
} catch (BindingResolutionException) {
}
}
return \Siteworx\Config\Config::load(__DIR__ . '/../../config.php');
}
@@ -38,6 +54,6 @@ class Config extends Facade
*/
protected static function getFacadeAccessor(): string
{
return 'config';
return \Siteworx\Config\Config::class;
}
}

View File

@@ -24,6 +24,15 @@ class Logger extends Facade
{
public static function getFacadeRoot(): RRLogger
{
if (self::$resolvedInstance !== null) {
$logger = self::resolveFacadeInstance(self::getFacadeAccessor());
if ($logger instanceof RRLogger) {
return $logger;
}
}
$rpc = RPC::create('tcp://127.0.0.1:6001');
return new RRLogger($rpc);

View File

@@ -13,10 +13,11 @@ use Nyholm\Psr7\Response;
*/
class JsonResponseFactory
{
/**
* Create a JSON response with the given data and status code.
*
* @param array $data The data to include in the response.
* @param mixed $data The data to include in the response.
* @param int $statusCode The HTTP status code for the response.
* @return Response The JSON response.
* @throws \JsonException
@@ -31,4 +32,4 @@ class JsonResponseFactory
body: json_encode($data, JSON_THROW_ON_ERROR)
);
}
}
}

View File

@@ -40,7 +40,7 @@ class CorsMiddleware implements MiddlewareInterface
$allowOrigin = in_array($origin, $allowedOrigins, true)
? $origin
: 'null';
: null;
if ($request->getMethod() === 'OPTIONS') {
$response = new Response(204);
@@ -48,6 +48,10 @@ class CorsMiddleware implements MiddlewareInterface
$response = $handler->handle($request);
}
if ($allowOrigin === null) {
return $response; // Do not add CORS headers if origin is not allowed.
}
$response = $response
->withHeader('Access-Control-Allow-Origin', $allowOrigin)
->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE, OPTIONS')
@@ -61,8 +65,9 @@ class CorsMiddleware implements MiddlewareInterface
$response = $response->withHeader('Access-Control-Allow-Credentials', 'true');
}
$maxAge = Config::get('CORS_MAX_AGE') !== 3600 ? Config::get('CORS_MAX_AGE') : 3600;
$maxAge = Config::get('cors.max_age') ?: '86400'; // Use correct configuration key.
return $response->withHeader('Access-Control-Max-Age', $maxAge);
}
}

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace Siteworxpro\App;
use Illuminate\Container\Container;
use Illuminate\Support\Facades\Facade;
use League\Route\Http\Exception\MethodNotAllowedException;
use League\Route\Http\Exception\NotFoundException;
use League\Route\Router;
@@ -58,6 +60,9 @@ class Server
*/
private function boot(): void
{
$container = new Container();
Facade::setFacadeApplication($container);
$this->worker = new PSR7Worker(
Worker::create(),
new Psr17Factory(),