{"id":21674340,"url":"https://github.com/drunomics/multisite-request-matcher","last_synced_at":"2025-04-12T04:22:18.943Z","repository":{"id":47667887,"uuid":"176303070","full_name":"drunomics/multisite-request-matcher","owner":"drunomics","description":"Matches requests to multisite hosts.","archived":false,"fork":false,"pushed_at":"2025-04-08T13:30:53.000Z","size":36,"stargazers_count":7,"open_issues_count":4,"forks_count":1,"subscribers_count":1,"default_branch":"1.x","last_synced_at":"2025-04-11T18:57:23.486Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drunomics.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-18T14:25:38.000Z","updated_at":"2023-06-08T14:12:21.000Z","dependencies_parsed_at":"2024-02-02T18:25:00.504Z","dependency_job_id":"f9507691-9ac9-4394-b9fe-711a423198a4","html_url":"https://github.com/drunomics/multisite-request-matcher","commit_stats":{"total_commits":46,"total_committers":7,"mean_commits":6.571428571428571,"dds":0.5434782608695652,"last_synced_commit":"367873228b59f68d18aaa034d45b4610d87b4c07"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drunomics%2Fmultisite-request-matcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drunomics%2Fmultisite-request-matcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drunomics%2Fmultisite-request-matcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drunomics%2Fmultisite-request-matcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drunomics","download_url":"https://codeload.github.com/drunomics/multisite-request-matcher/tar.gz/refs/heads/1.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248514532,"owners_count":21116977,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-25T13:44:09.289Z","updated_at":"2025-04-12T04:22:18.918Z","avatar_url":"https://github.com/drunomics.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Multisite Request Matcher\n\nMatches requests to multisites based upon configuration driven by environment variables.\nThe packages works well with symfony/dotenv and symfony/http-foundation as used by drupal/core.\n\nThe multisite setup supports configuration via a common base-domain ($APP_MULTISITE_DOMAIN) or via\nper site domains. Via environment-dependent variables the common base-domain may be enabled for preview\nenvironments only also. The configured default site is used when the common multisite base-domain is accessed without\nany suiting prefix. Next, it's used for CLI invocations if no SITE variable is given a.\n\n## Installation\n\n    composer require drunomics/multisite-request-matcher\n\n## Configuration\n\nThe package support construction site URLs via via a common base-domain ($APP_MULTISITE_DOMAIN) or via per site domains.\nOptional, site variants like \"admin\" or \"api\" are supported - useful if the app uses multiple hosts for things like the\nadmin interface or an API endpoint.\n\nThat can be used to construct URLs like the following:\n\n- Commom multisite domain:\n\n        https://site-a_stage.example.com\n        https://site-b_stage.example.com\n\n- Per site domains:\n\n        https://www.site-a.com\n        https://wwww.site-b.com\n\n- Common multisite domain with variants:\n\n        https://api--site-a_stage.example.com\n        https://api--site-b_stage.example.com\n        https://admin--site-a_stage.example.com\n        https://admin--site-b_stage.example.com\n\n- Per site domains with variants:\n\n        https://api.site-a.com\n        https://api.site-b.com\n        https://admin.site-a.com\n        https://admin.site-b.com\n\n\nThe following environment variables may be set to configure the request matcher:\n\n| Variable name | Required | Example Value | Description |\n| ------------- | -------- | ------------- | ------------|\n| TRUSTED_PROXIES | No |  127.0.0.1 | A list of IP addresses or subnets, separated by space. |\n| HEADER_FORWARDED_HOST | No | X_FORWARDED_HOST | A non-standard value for the host header. | \n| APP_SITES | Yes | site-a site-b | The list of site names, separated by space. May contain lowercase characters and dashes only. |\n| APP_DEFAULT_SITE | No | site-a | The default site to set. If not set, the first set will be set by default. |\n| APP_SITE_VARIANTS| No | admin api | An optional list of variants; i.e. variants of the same site.|\n| APP_SITE_VARIANT_SEPARATOR | No | -- | The separator between the variant name and the host, defaults to \"--\". |\n| APP_MULTISITE_DOMAIN | ~ | stage.codebase.dev | A common base domain for all sites. Required when multisite base domains should be used. |\n| APP_MULTISITE_DOMAIN_PREFIX_SEPARATOR | No | _ | The separator between the site name and the common multisite base domain. Defaults to '_'. |\n| 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` |\n| APP_SITE_DOMAIN_ALIASES__{{ SITE }} | No | site-a.hoster.com,site-a.hoster.com | Comma separated, per-site domain aliases that are allowed in addition to the main domain. Useful when access should be allowed via some non-primary domains also; e.g., when behind a CDN. 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_ALIASES__site_a` |\n| APP_SITE_DOMAIN | ~ | site-a.com | If an environment is bound to a fixed site, the site's domain. Requires SITE to be predefined. |\n| APP_SITE_DOMAIN_ALIASES | No | site-a.host.com,site-a.host2.com | If an environment is bound to a fixed site, the site's domain aliases (see above). Requires SITE to be predefined. |\n\n## Results\n\n- The matched host is set as trusted host to the symfony/http-foundation request API via trusted host patterns.\n- The following environment variables are set:\n\n| Variable name | Example Value | Description |\n| ------------- | ------------- | ----------- |\n| SITE | site-a | The active site. |\n| SITE_VARIANT | api | The active site variant. Empty if no variant is active.|\n| SITE_HOST | api--site-b_stage.example.com | The site's full host for the active site and variant. |\n| SITE_MAIN_HOST | stage.example.com | The site's main host, without any variant. |\n\n## CLI invocations\n\nIn order to make the same environment variables available for CLI invocations, the package provides the binary\n`request-matcher-site-variables` which outputs them based upon the set `$SITE` variable. Site variants are not supported\nin CLI requests, thus SITE_VARIANT is is always empty.\n\n## Usage with Drupal\n\n* Best, invoke the request matcher via the composer autoloader; that makes sure it is invoked very early and has matched\n  requests before anything else goes on. For an example refer to [this](https://github.com/drunomics/drupal-project/blob/4.x/composer.json#L58)\n  \n  Be sure your environment variables are set and invoke it like that:\n\n      $site = drunomics\\MultisiteRequestMatcher\\RequestMatcher::getInstance()\n        -\u003ematch();\n  \n* Add the following line to Drupal's sites.php such that Drupal can pick up the matched site. The site name of the\n  APP_SITES variable should match the Drupal site directory names:\n\n      $sites[$request-\u003egetHost()] = getenv('SITE');\n\n* Remove any trusted host patterns from Drupal as the request matcher already checked it.\n\n## Credits\n \n  developed by drunomics GmbH, hello@drunomics.com\n  Please refer to the commit log individual contributors. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrunomics%2Fmultisite-request-matcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrunomics%2Fmultisite-request-matcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrunomics%2Fmultisite-request-matcher/lists"}