92 lines
2.3 KiB
PHP
92 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use DI\ContainerBuilder;
|
|
use Slim\Factory\AppFactory;
|
|
use Dotenv\Dotenv;
|
|
use App\Middleware\CorsMiddleware;
|
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
|
use Psr\Http\Message\ResponseInterface as Response;
|
|
use App\Controllers\CaptchaController;
|
|
use App\Controllers\LoginController;
|
|
use App\Services\LxdService;
|
|
use Zounar\PHPProxy\Proxy;
|
|
use App\Utils\LogWriterHelper;
|
|
|
|
require __DIR__ . '/../vendor/autoload.php';
|
|
|
|
// 🔹 Load .env config
|
|
$dotenv = Dotenv::createImmutable(__DIR__ . '/../');
|
|
$dotenv->load();
|
|
|
|
$domain = $_ENV['MAIN_COOKIE_DOMAIN'] ?? '.lxdapp.local';
|
|
session_set_cookie_params([
|
|
'lifetime' => 0,
|
|
'path' => '/',
|
|
'domain' => $domain,
|
|
'secure' => false, // set true if using HTTPS
|
|
'httponly' => true,
|
|
'samesite' => 'Lax',
|
|
]);
|
|
|
|
if (session_status() === PHP_SESSION_NONE) {
|
|
session_start();
|
|
}
|
|
|
|
// Build Container using PHP-DI
|
|
$containerBuilder = new ContainerBuilder();
|
|
$containerBuilder->useAutowiring(true); // Enable autowiring globally
|
|
|
|
|
|
// Add settings
|
|
$settings = require __DIR__ . '/../src/Settings/Settings.php';
|
|
$settings($containerBuilder);
|
|
|
|
// Add dependencies
|
|
$dependencies = require __DIR__ . '/../src/Dependencies/Dependencies.php';
|
|
$dependencies($containerBuilder);
|
|
|
|
// Build the container
|
|
$container = $containerBuilder->build();
|
|
|
|
// Set container to AppFactory
|
|
AppFactory::setContainer($container);
|
|
|
|
// Create App
|
|
$app = AppFactory::create();
|
|
|
|
// 🔹 CORS middleware
|
|
$app->add(CorsMiddleware::class);
|
|
|
|
|
|
// Register middleware
|
|
(require __DIR__ . '/../src/Bootstrap/Middleware.php')($app);
|
|
|
|
|
|
// Register routes
|
|
|
|
// API contianer proxy route
|
|
$app->group('/api', function ($group) {
|
|
$group->get('/captcha', [CaptchaController::class, 'get']);
|
|
$group->post('/login', [LoginController::class, 'index']);
|
|
$group->get('/status', [LoginController::class, 'status']);
|
|
|
|
});
|
|
|
|
/**
|
|
* JSON response helper
|
|
*/
|
|
function jsonResponse(Response $response, array $data, int $status = 200): Response {
|
|
$payload = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
|
$response->getBody()->write($payload);
|
|
|
|
return $response
|
|
->withHeader('Content-Type', 'application/json')
|
|
->withHeader('Access-Control-Allow-Origin', '*')
|
|
->withStatus($status);
|
|
}
|
|
|
|
// Run app
|
|
$app->run();
|