mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-25 23:04:51 +02:00
StaticController: Allow to access a lib's js assets
This commit is contained in:
parent
526af93de8
commit
f18cb7d112
@ -38,7 +38,29 @@ class StaticController
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$assetRoot = $library->getStaticAssetPath();
|
preg_match('~^(\w+)/~', $assetPath, $m);
|
||||||
|
switch ($m[1] ?? null) {
|
||||||
|
case 'js':
|
||||||
|
$assetPath = substr($assetPath, 3);
|
||||||
|
$assetRoot = $library->getJsAssetPath();
|
||||||
|
$contentType = 'text/javascript';
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'css':
|
||||||
|
$assetPath = substr($assetPath, 4);
|
||||||
|
$assetRoot = $library->getCssAssetPath();
|
||||||
|
$contentType = 'text/css';
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'static':
|
||||||
|
$assetPath = substr($assetPath, 7);
|
||||||
|
|
||||||
|
// `static/` is the default
|
||||||
|
default:
|
||||||
|
$assetRoot = $library->getStaticAssetPath();
|
||||||
|
$contentType = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (empty($assetRoot)) {
|
if (empty($assetRoot)) {
|
||||||
$app->getResponse()
|
$app->getResponse()
|
||||||
->setHttpResponseCode(404);
|
->setHttpResponseCode(404);
|
||||||
@ -79,7 +101,7 @@ class StaticController
|
|||||||
} else {
|
} else {
|
||||||
$app->getResponse()
|
$app->getResponse()
|
||||||
->setHeader('ETag', $eTag)
|
->setHeader('ETag', $eTag)
|
||||||
->setHeader('Content-Type', mime_content_type($filePath), true)
|
->setHeader('Content-Type', $contentType ?? mime_content_type($filePath), true)
|
||||||
->setHeader('Last-Modified', gmdate('D, d M Y H:i:s', $fileStat['mtime']) . ' GMT')
|
->setHeader('Last-Modified', gmdate('D, d M Y H:i:s', $fileStat['mtime']) . ' GMT')
|
||||||
->setBody(file_get_contents($filePath));
|
->setBody(file_get_contents($filePath));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user