Skip to content

Commit

Permalink
Assets cache. (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
robsontenorio authored Oct 16, 2023
1 parent 21d03a2 commit fb32f7b
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,30 @@
}
});

Route::get('/mary/asset', function (Request $request) {
if ($request->name) {
$extension = Str::of($request->name)->afterLast('.')->toString();
Route::middleware('cache.headers:public;max_age=2628000;etag')->get('/mary/asset', function (Request $request) {
if (! $request->name) {
abort(404);
}

if (Str::of($request->name)->contains('..')) {
abort(404);
}

$type = match ($extension) {
'js' => 'application/javascript',
'css' => 'text/css',
default => 'text/html'
};
$file = Str::of($request->name)->before('?')->toString();

return response(File::get(__DIR__ . "/../libs/{$request->name}"))->header('Content-Type', $type);
if (! File::exists(__DIR__ . "/../libs/{$file}")) {
abort(404);
}

abort(404);
$extension = Str::of($file)->afterLast('.')->toString();

$type = match ($extension) {
'js' => 'application/javascript',
'css' => 'text/css',
default => 'text/html'
};

return response(File::get(__DIR__ . "/../libs/{$file}"))->withHeaders([
'Content-Type' => $type,
]);
});

0 comments on commit fb32f7b

Please sign in to comment.