dishplanner/bootstrap/app.php
myrmidex 561750dc83 FOSS pivot: retire SaaS, demo, and APP_MODE plumbing (#37 #38 #39 #40 #41)
Remove Stripe/Cashier subscription billing, demo mode, and APP_MODE enum/helpers. Delete frontend-old/ and stale bin scripts. Adopt AGPL-3.0 (LICENSE.md, README, composer.json). Point Docker image, prod scripts, and README at forge.lvl0.xyz/lvl0/dishplanner.
2026-08-16 17:29:19 +02:00

63 lines
2.3 KiB
PHP

<?php
use App\Http\Middleware\ForceJsonResponse;
use App\Services\OutputService;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
api: __DIR__.'/../routes/api.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
// Apply ForceJsonResponse only to API routes
$middleware->api(ForceJsonResponse::class);
})
->withExceptions(function (Exceptions $exceptions) {
$exceptions->shouldRenderJsonWhen(function (Request $request, Throwable $e) {
if ($request->is('api/*')) {
return true;
}
return $request->expectsJson();
});
/** @var OutputService $outputService */
$outputService = resolve(OutputService::class);
$exceptions->render(function (ValidationException $e, Request $request) use ($outputService) {
if ($request->is('api/*') || $request->expectsJson()) {
return response()->json(
$outputService->response(false, null, [$e->getMessage()]),
404
);
}
});
$exceptions->render(function (NotFoundHttpException $e, Request $request) use ($outputService) {
if ($request->is('api/*') || $request->expectsJson()) {
return response()->json(
$outputService->response(false, null, ['MODEL_NOT_FOUND']),
404
);
}
});
$exceptions->render(function (AccessDeniedHttpException $e, Request $request) use ($outputService) {
if ($request->is('api/*') || $request->expectsJson()) {
return response()->json(
$outputService->response(false, null, [$e->getMessage()]),
403
);
}
});
})
->create();