Skip to content

Commit

Permalink
Bugfix: Dashes in environment variable names are not allowed, replace…
Browse files Browse the repository at this point in the history
… dashes in site names with underscores.
  • Loading branch information
fago committed Jul 8, 2019
1 parent 23afe34 commit b35163e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ The following environment variables may be set to configure the request matcher:
| APP_SITE_VARIANT_SEPARATOR | No | -- | The separator between the variant name and the host, defaults to "--". |
| APP_MULTISITE_DOMAIN | ~ | stage.codebase.dev | A common base domain for all sites. Required when multisite base domains should be used. |
| APP_MULTISITE_DOMAIN_PREFIX_SEPARATOR | No | _ | The separator between the site name and the common multisite base domain. Defaults to '_'. |
| APP_SITE_DOMAIN__{{ SITE }} | ~ | site-a.com | The per-site domain - required when per-site domains should be used. One variable per site must be provided, e.g. for site-a the variable name would be `APP_SITE_DOMAIN__site-a` |
| APP_SITE_DOMAIN__{{ SITE }} | ~ | site-a.com | The per-site domain - required when per-site domains should be used. One variable per site must be provided with dashes replaced to underscores, e.g. for site-a the variable name would be `APP_SITE_DOMAIN__site_a` |

## Results

Expand Down
2 changes: 1 addition & 1 deletion src/RequestMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public function match(Request $request = NULL) {
$matches = [];
$variants = implode('|', $this->variants);
foreach ($this->sites as $current_site) {
$site_domain = getenv('APP_SITE_DOMAIN__' . $current_site);
$site_domain = getenv('APP_SITE_DOMAIN__' . str_replace('-', '_', $current_site));
if (empty($site_domain)) {
throw new RequestMatchException("Missing API_SITE_DOMAIN environment variable for site " . strip_tags($current_site) . ".");
}
Expand Down
8 changes: 4 additions & 4 deletions tests/src/RequestMatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public function testMatch() {
putenv("APP_SITE_VARIANTS=api admin");
putenv("APP_DEFAULT_SITE=site-a");
putenv("APP_SITES=site-a site-b");
putenv("APP_SITE_DOMAIN__site-a=site-a.com");
putenv("APP_SITE_DOMAIN__site-b=site-b.com");
putenv("APP_SITE_DOMAIN__site_a=site-a.com");
putenv("APP_SITE_DOMAIN__site_b=site-b.com");
$this->assertHostMatches('site-a.com', 'site-a', '');
$this->assertHostMatches('api.site-a.com', 'site-a', 'api');
$this->assertHostMatches('admin.site-a.com', 'site-a', 'admin');
Expand All @@ -71,8 +71,8 @@ public function testMatch() {
putenv("APP_SITE_VARIANT_SEPARATOR=.");
putenv("APP_DEFAULT_SITE=site-a");
putenv("APP_SITES=site-a site-b");
putenv("APP_SITE_DOMAIN__site-a=site-a.com");
putenv("APP_SITE_DOMAIN__site-b=site-b.com");
putenv("APP_SITE_DOMAIN__site_a=site-a.com");
putenv("APP_SITE_DOMAIN__site_b=site-b.com");
$this->assertHostMatches('site-a.com', 'site-a', '');
$this->assertHostMatches('site-b.com', 'site-b', '');
$this->assertHostDoesNotMatch('com');
Expand Down

0 comments on commit b35163e

Please sign in to comment.