Files
parsaaghayi-backend/bootstrap/app.php
T
Parsa Aghayi 6b03c0fbc3 Add a locked-down image upload endpoint for the admin panel
Posts, projects and about-me all carry an image column that could only ever
be filled by typing a URL by hand, so every featured image in the database is
still a placeholder. Uploads are the missing half of content management.

Filenames are generated rather than reused from the client, which is what
keeps a double extension or a path traversal out of a web-served directory.
The upload surface is restricted to raster formats (no SVG, which can carry
script) with a size and dimension ceiling, and throttled at 12/min against
the general admin API's 30/min because an upload costs far more than a JSON
write.

Routes move to per-feature files registered from bootstrap/app.php, since
api.php had become a chokepoint for parallel work on this repo.
2026-10-01 17:41:49 -04:00

51 lines
2.1 KiB
PHP

<?php
use App\Http\Middleware\AuthenticateAdminPanelSession;
use App\Http\Middleware\EnsureUserIsAdmin;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Support\Facades\Route;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
api: __DIR__.'/../routes/api.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
// Content-management endpoints live in their own files so the public and
// legacy routes in api.php stay readable. `then:` does not inherit the
// `api:` prefix or middleware group from the arguments above, so both
// are applied explicitly here to keep these routes identical in shape
// to the ones declared in routes/api.php.
then: function () {
Route::prefix('api')->middleware('api')->group(base_path('routes/media.php'));
Route::prefix('api')->middleware('api')->group(base_path('routes/crud.php'));
},
)
->withMiddleware(function (Middleware $middleware) {
// Let the Next.js admin panel authenticate with a Sanctum session
// cookie issued on the same registrable domain, instead of shipping a
// bearer token to JavaScript.
$middleware->statefulApi();
$middleware->api(prepend: [
AuthenticateAdminPanelSession::class,
]);
$middleware->alias([
'admin' => EnsureUserIsAdmin::class,
]);
// This is an API-only application with no `login` route. Without this,
// an unauthenticated write request that does not advertise JSON (a
// plain form POST or curl) resolves `route('login')` and dies with
// "Route [login] not defined" instead of a 401.
$middleware->redirectGuestsTo(fn () => null);
})
->withExceptions(function (Exceptions $exceptions) {
$exceptions->shouldRenderJsonWhen(
fn ($request) => $request->is('api/*') || $request->expectsJson()
);
})->create();