Some checks are pending
Deploy / deploy (push) Waiting to run
Move all files from deploy/ to project root, replace .gitlab-ci.yml with .forgejo/workflows/deploy.yml using Gitea Actions format. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
62 lines
1.6 KiB
PHP
62 lines
1.6 KiB
PHP
<?php
|
|
|
|
// Autoloader simple
|
|
spl_autoload_register(function ($class) {
|
|
$prefix = 'Web2Print\\';
|
|
$baseDir = __DIR__ . '/../src/';
|
|
|
|
$len = strlen($prefix);
|
|
if (strncmp($prefix, $class, $len) !== 0) {
|
|
return;
|
|
}
|
|
|
|
$relativeClass = substr($class, $len);
|
|
$file = $baseDir . str_replace('\\', '/', $relativeClass) . '.php';
|
|
|
|
if (file_exists($file)) {
|
|
require $file;
|
|
}
|
|
});
|
|
|
|
// Charger la configuration
|
|
$config = require __DIR__ . '/../config/config.php';
|
|
|
|
// Router simple
|
|
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
|
|
|
// Afficher la documentation sur la racine
|
|
if ($uri === '/' && $_SERVER['REQUEST_METHOD'] === 'GET') {
|
|
readfile(__DIR__ . '/docs.html');
|
|
exit;
|
|
}
|
|
|
|
// Définir le temps d'exécution max
|
|
set_time_limit($config['max_execution_time']);
|
|
|
|
// Headers CORS (si nécessaire)
|
|
header('Access-Control-Allow-Origin: *');
|
|
header('Access-Control-Allow-Methods: POST, OPTIONS');
|
|
header('Access-Control-Allow-Headers: Content-Type, X-API-Key');
|
|
|
|
// Gérer preflight OPTIONS
|
|
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
|
http_response_code(200);
|
|
exit;
|
|
}
|
|
|
|
// Authentification
|
|
$auth = new \Web2Print\Middleware\AuthMiddleware($config);
|
|
if (!$auth->authenticate()) {
|
|
exit;
|
|
}
|
|
|
|
// Endpoint de génération PDF
|
|
if ($uri === '/generate') {
|
|
$generator = new \Web2Print\Services\PdfGenerator($config);
|
|
$controller = new \Web2Print\Controllers\GenerateController($generator, $config);
|
|
$controller->handle();
|
|
} else {
|
|
http_response_code(404);
|
|
header('Content-Type: application/json');
|
|
echo json_encode(['error' => 'Not found']);
|
|
}
|