Skip to content

Commit

Permalink
Merge pull request #18 from craftcms/feature/webalias
Browse files Browse the repository at this point in the history
Adds @web alias checks for site and asset base urls
  • Loading branch information
angrybrad authored Apr 17, 2022
2 parents d787e1b + e431d7e commit 1ed5b5d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog for Craft CMS Server Check

## Unreleased

### Added
- Added checks for relying on the default `@web` alias.

## 1.2.1 - 2021-05-25

### Added
Expand Down
22 changes: 22 additions & 0 deletions server/requirements/RequirementsChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,28 @@ function maxExecutionTimeRequirement()
);
}

/**
* @return array
*/
function webAliasRequirement()
{
$aliases = Craft::$app->getConfig()->getGeneral()->aliases;
$memo = 'We recommend explicitly overriding the <a rel="noopener" target="_blank" href="https://craftcms.com/docs/3.x/config/#aliases">@web alias</a>.';
$pass = false;

if (isset($aliases['web']) || isset($aliases['@web'])) {
$memo = 'Your @web alias is set correctly';
$pass = true;
}

return array(
'name' => 'Ensure @web alias is explicitly overridden',
'mandatory' => false,
'condition' => $pass,
'memo' => $memo,
);
}

/**
* @return array
*/
Expand Down
1 change: 1 addition & 0 deletions server/requirements/requirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
// Only run this requirement check if we're running in the context of Craft.
if (class_exists('Craft')) {
$requirements[] = $this->webrootRequirement();
$requirements[] = $this->webAliasRequirement();
}

$requirements = array_merge($requirements, array(
Expand Down

0 comments on commit 1ed5b5d

Please sign in to comment.