diff --git a/routes/web.php b/routes/web.php index bbf6039..d72b935 100644 --- a/routes/web.php +++ b/routes/web.php @@ -38,6 +38,26 @@ ]); })->where('path', '.*'); +// R2 테넌트 파일 프록시 (문서 템플릿 이미지 등, 인증 불필요, 캐시 1일) +Route::get('/storage/tenants/{path}', function (string $path) { + if (! Storage::disk('r2')->exists($path)) { + abort(404); + } + + $mime = Storage::disk('r2')->mimeType($path); + $stream = Storage::disk('r2')->readStream($path); + + return response()->stream(function () use ($stream) { + fpassthru($stream); + if (is_resource($stream)) { + fclose($stream); + } + }, 200, [ + 'Content-Type' => $mime, + 'Cache-Control' => 'public, max-age=86400', + ]); +})->where('path', '.*'); + // Swagger 설정 Route::get('/docs/api-docs.json', function () { return response()->file(storage_path('api-docs/api-docs.json'));