Initial commit
This commit is contained in:
commit
2b89c4acd9
15 changed files with 3180 additions and 0 deletions
12
deploy/public/.htaccess
Normal file
12
deploy/public/.htaccess
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# Activer le moteur de réécriture
|
||||
RewriteEngine On
|
||||
|
||||
# Rediriger toutes les requêtes vers index.php
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteRule ^(.*)$ index.php [QSA,L]
|
||||
|
||||
# Sécurité
|
||||
<Files ".env">
|
||||
Require all denied
|
||||
</Files>
|
||||
251
deploy/public/assets/css/docs.css
Normal file
251
deploy/public/assets/css/docs.css
Normal file
|
|
@ -0,0 +1,251 @@
|
|||
:root {
|
||||
--color-bg: #ffffff;
|
||||
--color-surface: #f8f9fa;
|
||||
--color-border: #e1e4e8;
|
||||
--color-text: #24292e;
|
||||
--color-text-muted: #586069;
|
||||
--color-primary: #0366d6;
|
||||
--color-primary-dark: #0256c4;
|
||||
--color-success: #28a745;
|
||||
--color-code-bg: #f6f8fa;
|
||||
--spacing-xs: 0.25rem;
|
||||
--spacing-sm: 0.5rem;
|
||||
--spacing-md: 1rem;
|
||||
--spacing-lg: 1.5rem;
|
||||
--spacing-xl: 2rem;
|
||||
--spacing-2xl: 3rem;
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
|
||||
line-height: 1.6;
|
||||
color: var(--color-text);
|
||||
background: var(--color-bg);
|
||||
}
|
||||
|
||||
header {
|
||||
background: var(--color-surface);
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
padding: var(--spacing-xl) 0;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 0 var(--spacing-lg);
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 2.5rem;
|
||||
font-weight: 600;
|
||||
margin-bottom: var(--spacing-sm);
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 1.75rem;
|
||||
font-weight: 600;
|
||||
margin: var(--spacing-2xl) 0 var(--spacing-lg);
|
||||
padding-bottom: var(--spacing-sm);
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
margin: var(--spacing-xl) 0 var(--spacing-md);
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
font-size: 1.25rem;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
main {
|
||||
padding: var(--spacing-2xl) 0;
|
||||
}
|
||||
|
||||
.intro {
|
||||
background: var(--color-surface);
|
||||
padding: var(--spacing-xl);
|
||||
border-radius: 6px;
|
||||
margin-bottom: var(--spacing-2xl);
|
||||
border: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.intro p {
|
||||
margin-bottom: var(--spacing-md);
|
||||
}
|
||||
|
||||
.intro p:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.endpoint {
|
||||
margin-bottom: var(--spacing-2xl);
|
||||
padding-bottom: var(--spacing-2xl);
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.endpoint:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.endpoint-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-md);
|
||||
margin-bottom: var(--spacing-lg);
|
||||
}
|
||||
|
||||
.method {
|
||||
display: inline-block;
|
||||
padding: var(--spacing-xs) var(--spacing-md);
|
||||
background: var(--color-success);
|
||||
color: white;
|
||||
font-weight: 600;
|
||||
font-size: 0.875rem;
|
||||
border-radius: 4px;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.path {
|
||||
font-family: monospace;
|
||||
font-size: 1.25rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.description {
|
||||
margin-bottom: var(--spacing-lg);
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-bottom: var(--spacing-xl);
|
||||
font-size: 0.9375rem;
|
||||
}
|
||||
|
||||
thead {
|
||||
background: var(--color-surface);
|
||||
}
|
||||
|
||||
th,
|
||||
td {
|
||||
padding: var(--spacing-md);
|
||||
text-align: left;
|
||||
border: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
th {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
|
||||
font-size: 0.875em;
|
||||
background: var(--color-code-bg);
|
||||
padding: 0.2em 0.4em;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
pre {
|
||||
background: #0d1117;
|
||||
padding: var(--spacing-lg);
|
||||
border-radius: 6px;
|
||||
overflow-x: auto;
|
||||
margin-bottom: var(--spacing-lg);
|
||||
}
|
||||
|
||||
pre code {
|
||||
background: none;
|
||||
padding: 0;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.tabs {
|
||||
display: flex;
|
||||
gap: var(--spacing-sm);
|
||||
margin-bottom: var(--spacing-md);
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.tab-button {
|
||||
padding: var(--spacing-sm) var(--spacing-lg);
|
||||
background: none;
|
||||
border: none;
|
||||
border-bottom: 2px solid transparent;
|
||||
cursor: pointer;
|
||||
font-size: 0.9375rem;
|
||||
font-weight: 500;
|
||||
color: var(--color-text-muted);
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.tab-button:hover {
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.tab-button.active {
|
||||
color: var(--color-primary);
|
||||
border-bottom-color: var(--color-primary);
|
||||
}
|
||||
|
||||
.tab-content {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.tab-content.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.badge {
|
||||
display: inline-block;
|
||||
padding: var(--spacing-xs) var(--spacing-sm);
|
||||
background: var(--color-surface);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 4px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.badge.required {
|
||||
background: #fff5f5;
|
||||
color: #d73a49;
|
||||
border-color: #d73a49;
|
||||
}
|
||||
|
||||
.badge.optional {
|
||||
background: #f1f8ff;
|
||||
color: var(--color-primary);
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
footer {
|
||||
margin-top: var(--spacing-2xl);
|
||||
padding: var(--spacing-xl) 0;
|
||||
border-top: 1px solid var(--color-border);
|
||||
text-align: center;
|
||||
color: var(--color-text-muted);
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.auth-info {
|
||||
background: #fff5d1;
|
||||
border: 1px solid #e4d500;
|
||||
border-radius: 6px;
|
||||
padding: var(--spacing-lg);
|
||||
margin-bottom: var(--spacing-xl);
|
||||
}
|
||||
|
||||
.auth-info strong {
|
||||
display: block;
|
||||
margin-bottom: var(--spacing-sm);
|
||||
}
|
||||
10
deploy/public/assets/css/highlight-github-dark.min.css
vendored
Normal file
10
deploy/public/assets/css/highlight-github-dark.min.css
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}/*!
|
||||
Theme: GitHub Dark
|
||||
Description: Dark theme as seen on github.com
|
||||
Author: github.com
|
||||
Maintainer: @Hirse
|
||||
Updated: 2021-05-15
|
||||
|
||||
Outdated base version: https://github.com/primer/github-syntax-dark
|
||||
Current colors taken from GitHub's CSS
|
||||
*/.hljs{color:#c9d1d9;background:#0d1117}.hljs-doctag,.hljs-keyword,.hljs-meta .hljs-keyword,.hljs-template-tag,.hljs-template-variable,.hljs-type,.hljs-variable.language_{color:#ff7b72}.hljs-title,.hljs-title.class_,.hljs-title.class_.inherited__,.hljs-title.function_{color:#d2a8ff}.hljs-attr,.hljs-attribute,.hljs-literal,.hljs-meta,.hljs-number,.hljs-operator,.hljs-selector-attr,.hljs-selector-class,.hljs-selector-id,.hljs-variable{color:#79c0ff}.hljs-meta .hljs-string,.hljs-regexp,.hljs-string{color:#a5d6ff}.hljs-built_in,.hljs-symbol{color:#ffa657}.hljs-code,.hljs-comment,.hljs-formula{color:#8b949e}.hljs-name,.hljs-quote,.hljs-selector-pseudo,.hljs-selector-tag{color:#7ee787}.hljs-subst{color:#c9d1d9}.hljs-section{color:#1f6feb;font-weight:700}.hljs-bullet{color:#f2cc60}.hljs-emphasis{color:#c9d1d9;font-style:italic}.hljs-strong{color:#c9d1d9;font-weight:700}.hljs-addition{color:#aff5b4;background-color:#033a16}.hljs-deletion{color:#ffdcd7;background-color:#67060c}
|
||||
1213
deploy/public/assets/js/highlight.min.js
vendored
Normal file
1213
deploy/public/assets/js/highlight.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
320
deploy/public/docs.html
Normal file
320
deploy/public/docs.html
Normal file
|
|
@ -0,0 +1,320 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Web2Print API Documentation</title>
|
||||
<link rel="stylesheet" href="/assets/css/docs.css">
|
||||
<link rel="stylesheet" href="/assets/css/highlight-github-dark.min.css">
|
||||
<script src="/assets/js/highlight.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<div class="container">
|
||||
<h1>Web2Print API</h1>
|
||||
<p class="subtitle">Générez des PDF à partir de HTML avec Paged.js</p>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="container">
|
||||
<section class="intro">
|
||||
<h2>Introduction</h2>
|
||||
<p>
|
||||
L'API Web2Print permet de générer des documents PDF de haute qualité à partir de contenu HTML.
|
||||
Elle utilise <strong>Paged.js</strong> pour appliquer les standards CSS Paged Media,
|
||||
offrant un contrôle précis sur la mise en page, les sauts de page, les en-têtes, les pieds de page et bien plus.
|
||||
</p>
|
||||
<p>
|
||||
Cette API est conçue pour être simple d'utilisation tout en offrant une grande flexibilité
|
||||
pour créer des documents professionnels tels que rapports, factures, catalogues ou livres.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section class="auth-info">
|
||||
<strong>🔐 Authentification requise</strong>
|
||||
<p>
|
||||
Toutes les requêtes doivent inclure un header <code>X-API-Key</code> avec une clé API valide.
|
||||
Contactez l'administrateur pour obtenir votre clé d'accès.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<h2>Endpoints</h2>
|
||||
|
||||
<article class="endpoint">
|
||||
<div class="endpoint-header">
|
||||
<span class="method">POST</span>
|
||||
<span class="path">/generate</span>
|
||||
</div>
|
||||
|
||||
<p class="description">
|
||||
Génère un document PDF à partir de contenu HTML. Le HTML peut inclure des styles inline
|
||||
ou dans une balise <code><style></code>. CSS additionnel peut être fourni via le paramètre <code>css</code>.
|
||||
</p>
|
||||
|
||||
<h3>Paramètres</h3>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Paramètre</th>
|
||||
<th>Type</th>
|
||||
<th>Requis</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code>html</code></td>
|
||||
<td>string</td>
|
||||
<td><span class="badge required">Requis</span></td>
|
||||
<td>Contenu HTML du document à convertir en PDF</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>css</code></td>
|
||||
<td>string</td>
|
||||
<td><span class="badge optional">Optionnel</span></td>
|
||||
<td>Styles CSS additionnels à appliquer au document</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>options</code></td>
|
||||
<td>object</td>
|
||||
<td><span class="badge optional">Optionnel</span></td>
|
||||
<td>Options de configuration pour la génération PDF</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h3>Headers requis</h3>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Header</th>
|
||||
<th>Valeur</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code>Content-Type</code></td>
|
||||
<td><code>application/json</code></td>
|
||||
<td>Type de contenu de la requête</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>X-API-Key</code></td>
|
||||
<td>Votre clé API</td>
|
||||
<td>Clé d'authentification</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h3>Réponse</h3>
|
||||
<p class="description">
|
||||
En cas de succès, l'API retourne le fichier PDF binaire avec le header <code>Content-Type: application/pdf</code>.
|
||||
En cas d'erreur, elle retourne un JSON avec un objet <code>error</code>.
|
||||
</p>
|
||||
|
||||
<h3>Exemples de code</h3>
|
||||
|
||||
<div class="tabs">
|
||||
<button class="tab-button active" data-tab="curl">cURL</button>
|
||||
<button class="tab-button" data-tab="javascript">JavaScript</button>
|
||||
<button class="tab-button" data-tab="python">Python</button>
|
||||
<button class="tab-button" data-tab="php">PHP</button>
|
||||
</div>
|
||||
|
||||
<div class="tab-content active" id="curl">
|
||||
<pre><code class="language-bash">curl -X POST https://web2print.studio-variable.com/generate \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-API-Key: YOUR_API_KEY" \
|
||||
-d '{
|
||||
"html": "<!DOCTYPE html><html><head><meta charset=\"utf-8\"><style>@page { size: A4; margin: 2cm; } body { font-family: Arial; } h1 { color: #333; }</style></head><body><h1>Mon Document</h1><p>Contenu du document.</p></body></html>"
|
||||
}' \
|
||||
--output document.pdf</code></pre>
|
||||
</div>
|
||||
|
||||
<div class="tab-content" id="javascript">
|
||||
<pre><code class="language-javascript">const response = await fetch('https://web2print.studio-variable.com/generate', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-API-Key': 'YOUR_API_KEY'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
html: `<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<style>
|
||||
@page { size: A4; margin: 2cm; }
|
||||
body { font-family: Arial; }
|
||||
h1 { color: #333; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Mon Document</h1>
|
||||
<p>Contenu du document.</p>
|
||||
</body>
|
||||
</html>`
|
||||
})
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const blob = await response.blob();
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = 'document.pdf';
|
||||
a.click();
|
||||
} else {
|
||||
const error = await response.json();
|
||||
console.error('Erreur:', error);
|
||||
}</code></pre>
|
||||
</div>
|
||||
|
||||
<div class="tab-content" id="python">
|
||||
<pre><code class="language-python">import requests
|
||||
|
||||
url = 'https://web2print.studio-variable.com/generate'
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'X-API-Key': 'YOUR_API_KEY'
|
||||
}
|
||||
data = {
|
||||
'html': '''<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<style>
|
||||
@page { size: A4; margin: 2cm; }
|
||||
body { font-family: Arial; }
|
||||
h1 { color: #333; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Mon Document</h1>
|
||||
<p>Contenu du document.</p>
|
||||
</body>
|
||||
</html>'''
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=data)
|
||||
|
||||
if response.status_code == 200:
|
||||
with open('document.pdf', 'wb') as f:
|
||||
f.write(response.content)
|
||||
print('PDF généré avec succès')
|
||||
else:
|
||||
print('Erreur:', response.json())</code></pre>
|
||||
</div>
|
||||
|
||||
<div class="tab-content" id="php">
|
||||
<pre><code class="language-php">$ch = curl_init('https://web2print.studio-variable.com/generate');
|
||||
|
||||
$html = '<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<style>
|
||||
@page { size: A4; margin: 2cm; }
|
||||
body { font-family: Arial; }
|
||||
h1 { color: #333; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Mon Document</h1>
|
||||
<p>Contenu du document.</p>
|
||||
</body>
|
||||
</html>';
|
||||
|
||||
$data = json_encode(['html' => $html]);
|
||||
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'Content-Type: application/json',
|
||||
'X-API-Key: YOUR_API_KEY'
|
||||
],
|
||||
CURLOPT_POSTFIELDS => $data
|
||||
]);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
if ($httpCode === 200) {
|
||||
file_put_contents('document.pdf', $response);
|
||||
echo 'PDF généré avec succès';
|
||||
} else {
|
||||
$error = json_decode($response, true);
|
||||
echo 'Erreur: ' . $error['error'];
|
||||
}</code></pre>
|
||||
</div>
|
||||
|
||||
<h3>Codes de réponse HTTP</h3>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Code</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code>200</code></td>
|
||||
<td>Succès - Le PDF est retourné dans le corps de la réponse</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>400</code></td>
|
||||
<td>Requête invalide - JSON mal formé ou paramètre manquant</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>401</code></td>
|
||||
<td>Non autorisé - Clé API manquante ou invalide</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>405</code></td>
|
||||
<td>Méthode non autorisée - Seul POST est accepté</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>413</code></td>
|
||||
<td>Requête trop volumineuse - Le contenu HTML dépasse la limite</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>500</code></td>
|
||||
<td>Erreur serveur - Erreur lors de la génération du PDF</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</article>
|
||||
</main>
|
||||
|
||||
<footer class="container">
|
||||
<p>Web2Print API © 2024 - Propulsé par Paged.js</p>
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
// Gestion des onglets
|
||||
document.querySelectorAll('.tab-button').forEach(button => {
|
||||
button.addEventListener('click', () => {
|
||||
const tabName = button.dataset.tab;
|
||||
const tabGroup = button.closest('.endpoint');
|
||||
|
||||
// Désactiver tous les onglets et contenus
|
||||
tabGroup.querySelectorAll('.tab-button').forEach(btn => {
|
||||
btn.classList.remove('active');
|
||||
});
|
||||
tabGroup.querySelectorAll('.tab-content').forEach(content => {
|
||||
content.classList.remove('active');
|
||||
});
|
||||
|
||||
// Activer l'onglet et le contenu sélectionnés
|
||||
button.classList.add('active');
|
||||
tabGroup.querySelector(`#${tabName}`).classList.add('active');
|
||||
});
|
||||
});
|
||||
|
||||
// Highlight.js
|
||||
hljs.highlightAll();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
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