docs: Add module guide dan security guidelines untuk API documentation

This commit is contained in:
mwpn
2025-12-17 11:11:26 +07:00
parent c7bfaee618
commit 220b554a17
3 changed files with 323 additions and 7 deletions

View File

@@ -27,36 +27,38 @@ $app->get('/', function ($request, $response) {
});
// Docs route - serve Swagger UI
// NOTE: Saat ini PUBLIC. Jika perlu protect, tambahkan JwtMiddleware atau IpWhitelistMiddleware
$app->get('/docs', function ($request, $response) {
$docsPath = __DIR__ . '/docs/index.html';
if (!file_exists($docsPath)) {
$response->getBody()->write('<h1>Documentation not found</h1>');
return $response
->withStatus(404)
->withHeader('Content-Type', 'text/html');
}
$html = file_get_contents($docsPath);
$response->getBody()->write($html);
return $response->withHeader('Content-Type', 'text/html');
});
// Serve OpenAPI JSON
// NOTE: Saat ini PUBLIC. Jika perlu protect, tambahkan middleware
$app->get('/docs/openapi.json', function ($request, $response) {
$openApiPath = __DIR__ . '/docs/openapi.json';
if (!file_exists($openApiPath)) {
$response->getBody()->write(json_encode(['error' => 'OpenAPI spec not found']));
return $response
->withStatus(404)
->withHeader('Content-Type', 'application/json');
}
$json = file_get_contents($openApiPath);
$response->getBody()->write($json);
return $response->withHeader('Content-Type', 'application/json');
});
@@ -70,4 +72,3 @@ RealtimeRoutes::register($app);
// Run application
$app->run();