How can I set an alias dynamically based on request? I have a multi-domain setup where I run multiple one-pager sites from different domains. For development purposes, I have configured it to work like this:
dev has:
http://localhost/www.domain1.com
http://localhost/www.domain2.com

staging has:
https://stage.ourdomain.com/www.domain1.com
https://stage.ourdomain.com/www.domain2.com

and production has:
https://www.domain1.com
https://www.domain2.com

To achieve this with the same site configuration for all three envs, I have created an alias called @baseUrlPrefix that I use in the site configuration (as part of the base URL), so for each env they are set to:
dev: http://localhost
stage: https://stage.ourdomain.com
prod: https:

And for each site I do @baseUrlPrefix//www.domain1.com (etc)
This has all worked fine and all, but I ran into issues when my devs had to do testing from mobile devices, because their local environment would only respond to localhost URLs. So I made a change for our dev config, to do (inspired by https://github.com/craftcms/cms/issues/2486):
use yii\web\Request;
$request = new Request;
...
'@baseUrlPrefix' =&gt; $request-&gt;getHostInfo(),

Which has also worked, no problem up until I'm trying to upgrade craft (this works in 3.3.15-18), and onwards from 3.3.19 it seems, it throws because it can't find Yii. It seems like maybe the loading order has changed, or I'm doing something incredibly stupid. I read that @web is supposed to actually take care  of this, which it also does, so using @web/www.domain1.com does work as intended, and I can overwrite that alias on production and set it to https:.
BUT, I also read that it's highly discouraged to use @web as siteUrl (https://craftcms.com/docs/3.x/sites.html#site-url) and I don't fully understand the implications of this, or if my use of an @alias is already suffering fromt he same cache poisoning bug?
As far as I know, using the @web alias is discouraged if its determined automatically (which is the default behavior).
If you override it with a hardcoded value in production I think you should be fine.

Edit
After checking the documentation, the warning is now pretty dissuasive against using the @web alias :

When you actually use it in a site's base URL setting in the control panel, the warning is a little more moderated:

I'm not sure if its because the documentation is more up to date or if it's actually fine to use it when overridden.