Initial commit
This commit is contained in:
commit
2b89c4acd9
15 changed files with 3180 additions and 0 deletions
62
deploy/public/index.php
Normal file
62
deploy/public/index.php
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<?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']);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue