Based on this answer, you can fetch baseurl from backend with his code:
This won't work properly, if settings 'Add Store Code to Urls' is set to 'Yes' (details about that). In this case, it will add 'admin' into url.
I noticed that also
won't display proper url, it will add admin into url on fresh Magento installation.
Is that Magento bug? Is there any other proper way to get frontend base url from backend?