aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/lib/SetupChecks/JavaScriptModules.php
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2024-02-15 02:07:01 +0100
committerFerdinand Thiessen <opensource@fthiessen.de>2024-02-15 02:17:16 +0100
commit096d66edc856be66d4c89c034e31f5b3b9170fd2 (patch)
tree767a1c1718e308bba58d154093c40a72953fd53b /apps/settings/lib/SetupChecks/JavaScriptModules.php
parent8cebd2b7c021d2f3f646070476e62876713623e5 (diff)
downloadnextcloud-server-096d66edc856be66d4c89c034e31f5b3b9170fd2.tar.gz
nextcloud-server-096d66edc856be66d4c89c034e31f5b3b9170fd2.zip
enh(settings): Add trait for setup checks that need to access the webserver using HTTP requests
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'apps/settings/lib/SetupChecks/JavaScriptModules.php')
-rw-r--r--apps/settings/lib/SetupChecks/JavaScriptModules.php41
1 files changed, 17 insertions, 24 deletions
diff --git a/apps/settings/lib/SetupChecks/JavaScriptModules.php b/apps/settings/lib/SetupChecks/JavaScriptModules.php
index 92e0035eedd..81f580a37bc 100644
--- a/apps/settings/lib/SetupChecks/JavaScriptModules.php
+++ b/apps/settings/lib/SetupChecks/JavaScriptModules.php
@@ -37,12 +37,14 @@ use Psr\Log\LoggerInterface;
* Checks if the webserver serves '.mjs' files using the correct MIME type
*/
class JavaScriptModules implements ISetupCheck {
+ use CheckServerResponseTrait;
+
public function __construct(
- private IL10N $l10n,
- private IConfig $config,
- private IURLGenerator $urlGenerator,
- private IClientService $clientService,
- private LoggerInterface $logger,
+ protected IL10N $l10n,
+ protected IConfig $config,
+ protected IURLGenerator $urlGenerator,
+ protected IClientService $clientService,
+ protected LoggerInterface $logger,
) {
}
@@ -56,28 +58,19 @@ class JavaScriptModules implements ISetupCheck {
public function run(): SetupResult {
$testFile = $this->urlGenerator->linkTo('settings', 'js/esm-test.mjs');
- $testURLs = array_merge(
- [$this->urlGenerator->getAbsoluteURL($testFile)],
- array_map(fn (string $host): string => $host . $testFile, $this->config->getSystemValue('trusted_domains', []))
- );
- foreach ($testURLs as $testURL) {
- try {
- $client = $this->clientService->newClient();
- $response = $client->head($testURL, [
- 'connect_timeout' => 10,
- 'nextcloud' => [
- 'allow_local_address' => true,
- ],
- ]);
- if (preg_match('/(text|application)\/javascript/i', $response->getHeader('Content-Type'))) {
- return SetupResult::success();
- }
- } catch (\Throwable $e) {
- $this->logger->debug('Can not connect to local server for checking JavaScript modules support', ['exception' => $e, 'url' => $testURL]);
- return SetupResult::warning($this->l10n->t('Could not check for JavaScript support. Please check manually if your webserver serves `.mjs` files using the JavaScript MIME type.'));
+ $noResponse = true;
+ foreach ($this->runHEAD($testFile) as $response) {
+ $noResponse = false;
+ if (preg_match('/(text|application)\/javascript/i', $response->getHeader('Content-Type'))) {
+ return SetupResult::success();
}
}
+
+ if ($noResponse) {
+ return SetupResult::warning($this->l10n->t('Could not check for JavaScript support. Please check manually if your webserver serves `.mjs` files using the JavaScript MIME type.') . "\n" . $this->serverConfigHelp());
+ }
return SetupResult::error($this->l10n->t('Your webserver does not serve `.mjs` files using the JavaScript MIME type. This will break some apps by preventing browsers from executing the JavaScript files. You should configure your webserver to serve `.mjs` files with either the `text/javascript` or `application/javascript` MIME type.'));
+
}
}