updates to M3 module
This commit is contained in:
@@ -39,11 +39,34 @@ use Modules\M3\Http\Controllers\WhsPerfMetrics;
|
||||
|
||||
|
||||
Route::get('/assets/{path}', function (string $path) {
|
||||
abort_if(str_contains($path, '..'), 404);
|
||||
$file = module_path('M3', 'Resources/public/' . $path);
|
||||
abort_unless(is_file($file), 404);
|
||||
return response()->file($file);
|
||||
})->where('path', '.*')->name('assets');
|
||||
abort_if(str_contains($path, '..') || str_contains($path, "\0"), 404);
|
||||
|
||||
$root = realpath(module_path('M3', 'Resources/public'));
|
||||
$file = realpath(module_path('M3', 'Resources/public/' . ltrim($path, '/')));
|
||||
|
||||
abort_unless($root && $file && str_starts_with($file, $root . DIRECTORY_SEPARATOR) && is_file($file), 404);
|
||||
|
||||
$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
|
||||
$contentTypes = [
|
||||
'css' => 'text/css; charset=UTF-8',
|
||||
'js' => 'application/javascript; charset=UTF-8',
|
||||
'svg' => 'image/svg+xml',
|
||||
'png' => 'image/png',
|
||||
'jpg' => 'image/jpeg',
|
||||
'jpeg' => 'image/jpeg',
|
||||
'gif' => 'image/gif',
|
||||
'ico' => 'image/x-icon',
|
||||
'woff' => 'font/woff',
|
||||
'woff2' => 'font/woff2',
|
||||
'ttf' => 'font/ttf',
|
||||
];
|
||||
|
||||
return response(file_get_contents($file), 200, [
|
||||
'Content-Type' => $contentTypes[$extension] ?? 'application/octet-stream',
|
||||
'Cache-Control' => app()->environment('local') ? 'no-cache, no-store, must-revalidate' : 'public, max-age=86400',
|
||||
'X-Content-Type-Options' => 'nosniff',
|
||||
]);
|
||||
})->where('path', '.+')->name('assets');
|
||||
|
||||
Route::get('/health', fn () => response()->json(['module' => 'M3', 'status' => 'ok', 'database' => config('m3.connection', 'pgsql')]))->name('health');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user