Perhaps this could be resolved by mapping APP_URL to my web middleware? Is this possible
Routing by Domain via Domains in Database
I need to route domains dynamically by domains pulled from my database. My current setup looks like this:
// domain handler
Route::domain('{userDomain}', function(){
Route::get('{fullPath}', function($domain, $fullPath){
// If the domain in the database handle it with the $fullPath
})
->where('fullPath', '.*');
});
// Typical app routes
Route::get('/', ...)
Route::get('/home', ...)
The problem that I am encountering is that my "typical" app routes and "domain-handled" routes conflict with one another. For example, the domain-handled routes may have a path of / which is also used by my homepage making handled-domain.com/ conflict with myapp.com/.
I thought I had this fixed by creating a middleware and adding this to my RouteServiceProvider::map():
/**
* Define the routes for the application.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function map(Router $router)
{
if(!$this->isMainAppDomain()) {
$this->mapVanityRoutes($router);
return;
}
$this->mapWebRoutes($router);
$this->mapApiRoutes($router);
//
}
The problem with this is that it is incompatible with tests. It seems the app is initiated with my APP_URL (main app URL) and in tests $this->refreshApplication() does not help.
In short, how do I route by domains in my database and prevent and prevent my main app routes from conflicting with these requests?
P.S. I tried Route::domain on my main app URLs, but this doesn't impact routes generated for the web middleware by vendors.
Please or to participate in this conversation.