Closed bakura10 closed 6 years ago
That's something you can do with nested middleware applications.
As an example, you can have pipeline middleware that checks against the host, and then dispatches another Expressive application based on the match:
$host = $request->getHeaderLine('Host');
switch (strtolower($host)) {
case 'api':
$api = $this->container->get('ApiApplication');
return $api($request, response, $next);
default:
return $next($request, $response);
}
Just a quick point of clarification: the path-based matching in pipeline middleware is a feature of Stratigility, which inherits the feature from Sencha Connect. Its primary purpose is path-based segregation; if you want to do host-based segregation, you either run the application on a separate host, or you use a solution like I outline above.
Sounds like a nice solution. But maybe Stratigility implementation could deviate a bit to add this feature? That sounds like a pretty simple feature, as today in Expressive there is basically no easy way through config to perform routing based on host.
@bakura10 I don't want to bloat Stratigility too much, but that should be relatively easy to add. Want to contribute a PR?
Yep will try to do that when I have a bit of time :).
Hey, has anyone worked on this feature? If not I'd be willing to submit PRs to Stratigility and Expressive to allow host based middleware pipe routing. @weierophinney
It's possible now with Expressive 3. See:
Hi,
Similar to how we can segregate by path:
Would it be possible to also segregate by host?