feat: [storage] R2 정적 이미지 프록시 라우트 추가
- /images/{path} 라우트로 R2에서 이미지 스트리밍
- bending 도면 이미지 등 정적 파일을 R2에서 서빙
- 캐시 1일 적용 (Cache-Control: max-age=86400)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
Route::get('/', function () {
|
||||
return redirect('/api-docs/index.html');
|
||||
@@ -15,6 +16,28 @@
|
||||
|
||||
});
|
||||
|
||||
// R2 정적 이미지 프록시 (인증 불필요, 캐시 1일)
|
||||
Route::get('/images/{path}', function (string $path) {
|
||||
$r2Path = 'images/'.$path;
|
||||
|
||||
if (! Storage::disk('r2')->exists($r2Path)) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$mime = Storage::disk('r2')->mimeType($r2Path);
|
||||
$stream = Storage::disk('r2')->readStream($r2Path);
|
||||
|
||||
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'));
|
||||
|
||||
Reference in New Issue
Block a user