drunomics / multisite-request-matcher
Matches requests to multisite hosts.
Installs: 33 500
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 2
Forks: 0
Open Issues: 3
Requires
- symfony/http-foundation: ^4.4.9 || ^6.2.7
Requires (Dev)
- phpunit/phpunit: 7.5.20
README
Matches requests to multisites based upon configuration driven by environment variables. The packages works well with symfony/dotenv and symfony/http-foundation as used by drupal/core.
The multisite setup supports configuration via a common base-domain ($APP_MULTISITE_DOMAIN) or via per site domains. Via environment-dependent variables the common base-domain may be enabled for preview environments only also. The configured default site is used when the common multisite base-domain is accessed without any suiting prefix. Next, it's used for CLI invocations if no SITE variable is given a.
Installation
composer require drunomics/multisite-request-matcher
Configuration
The package support construction site URLs via via a common base-domain ($APP_MULTISITE_DOMAIN) or via per site domains. Optional, site variants like "admin" or "api" are supported - useful if the app uses multiple hosts for things like the admin interface or an API endpoint.
That can be used to construct URLs like the following:
-
Commom multisite domain:
https://site-a_stage.example.com https://site-b_stage.example.com
-
Per site domains:
https://www.site-a.com https://wwww.site-b.com
-
Common multisite domain with variants:
https://api--site-a_stage.example.com https://api--site-b_stage.example.com https://admin--site-a_stage.example.com https://admin--site-b_stage.example.com
-
Per site domains with variants:
https://api.site-a.com https://api.site-b.com https://admin.site-a.com https://admin.site-b.com
The following environment variables may be set to configure the request matcher:
Results
- The matched host is set as trusted host to the symfony/http-foundation request API via trusted host patterns.
- The following environment variables are set:
CLI invocations
In order to make the same environment variables available for CLI invocations, the package provides the binary
request-matcher-site-variables
which outputs them based upon the set $SITE
variable. Site variants are not supported
in CLI requests, thus SITE_VARIANT is is always empty.
Usage with Drupal
-
Best, invoke the request matcher via the composer autoloader; that makes sure it is invoked very early and has matched requests before anything else goes on. For an example refer to this
Be sure your environment variables are set and invoke it like that:
$site = drunomics\MultisiteRequestMatcher\RequestMatcher::getInstance() ->match();
-
Add the following line to Drupal's sites.php such that Drupal can pick up the matched site. The site name of the APP_SITES variable should match the Drupal site directory names:
$sites[$request->getHost()] = getenv('SITE');
-
Remove any trusted host patterns from Drupal as the request matcher already checked it.
Credits
developed by drunomics GmbH, hello@drunomics.com Please refer to the commit log individual contributors.