Differences between cli and web

I have a plugin that is creating a search index and allowing a site-wide search.
To index the search I have a method that is called.
I have noticed a differences in how urls are displayed when in the cli context vs in the web context.

In the web context things like $anyPage->url() will return a FQDN like https://kirby.test/subpage.
Running the same method in the cli context will give me: //subpage for the url in the main language and for example /en/subpage for a secondary language.

I did not observe any other differences.

How can I make sure the url is right in the cli context so that reindexing can be automated via cron and not invoked via web?

Here are some excepts from the indexing logic to understand / replicate it:

// the command:
use Kirby\CLI\CLI;
use PZ\Kirby\Search\Search;

return [
	'description' => 'Reindex Search',
	'args'        => [],
	'command'     => function (CLI $cli) {
		$search = new Search();
		$timestamp = date('Y-m-d H:i:s T');

		try {
			$search->reindex();
			$cli->success('[' . $timestamp . '] Reindexing completed successfully.');
		} catch (\Throwable $th) {
			$cli->error('[' . $timestamp . '] An error occurred while reindexing: ' . $th->getMessage());

			return;
		}
	},
];
// the reindexing part:
public function reindex(): void
{
	foreach (kirby()->languages() as $lang) {
		// impersonate language user
		kirby()->setCurrentLanguage($lang->code());

		// get all pages
		$pages = kirby()->site()->index()->filter(function ($page) {
			return $page->algoliaSearchable()->toBool();
		});

		foreach ($pages as $value) {
			site()->log(dump($value));
		}

...

The log looks like this for one page:

DefaultPage Object
(
    [content] => Kirby\Content\Content Object
        (
            [title] => Testunterseite
            [layout] => 
            [seokeywords] => 
            [seodescription] => 
            [linkdescription] => 
            [linkimage] => 
            [robotsindex] => index
            [robotsfollow] => follow
            [organization] => 
            [algoliafieldsearchable] => true
            [algoliafieldranking] => 0
            [uuid] => Q2vXxDBJB6BCB8KS
        )

    [translations] => Kirby\Cms\Collection Object
        (
            [0] => de
            [1] => en
        )

    [children] => Kirby\Cms\Pages Object
        (
        )

    [files] => Kirby\Cms\Files Object
        (
        )

    [id] => verwaltung-und-politik/gremien/jugendbeirat/testunterseite
    [mediaUrl] => /media/pages/verwaltung-und-politik/gremien/jugendbeirat/testunterseite
    [mediaRoot] => /var/www/html/public/media/pages/verwaltung-und-politik/gremien/jugendbeirat/testunterseite
    [num] => 1
    [parent] => verwaltung-und-politik/gremien/jugendbeirat
    [slug] => testunterseite
    [template] => MinifyHTML Object
        (
            [defaultType:protected] => html
            [name:protected] => default
            [type:protected] => html
        )

    [uid] => testunterseite
    [uri] => verwaltung-und-politik/gremien/jugendbeirat/testunterseite
    [url] => //verwaltung-und-politik/gremien/jugendbeirat/testunterseite
    [siblings] => Kirby\Cms\Pages Object
        (
            [0] => verwaltung-und-politik/gremien/jugendbeirat/testunterseite
        )

)

// and in english:
DefaultPage Object
(
    [content] => Kirby\Content\Content Object
        (
            [title] => Testunterseite
            [layout] => 
            [seokeywords] => 
            [seodescription] => 
            [linkdescription] => 
            [linkimage] => 
            [robotsindex] => index
            [robotsfollow] => follow
            [organization] => 
            [algoliafieldsearchable] => true
            [algoliafieldranking] => 0
            [uuid] => Q2vXxDBJB6BCB8KS
        )

    [translations] => Kirby\Cms\Collection Object
        (
            [0] => de
            [1] => en
        )

    [children] => Kirby\Cms\Pages Object
        (
        )

    [files] => Kirby\Cms\Files Object
        (
        )

    [id] => verwaltung-und-politik/gremien/jugendbeirat/testunterseite
    [mediaUrl] => /media/pages/verwaltung-und-politik/gremien/jugendbeirat/testunterseite
    [mediaRoot] => /var/www/html/public/media/pages/verwaltung-und-politik/gremien/jugendbeirat/testunterseite
    [num] => 1
    [parent] => verwaltung-und-politik/gremien/jugendbeirat
    [slug] => testunterseite
    [template] => MinifyHTML Object
        (
            [defaultType:protected] => html
            [name:protected] => default
            [type:protected] => html
        )

    [uid] => testunterseite
    [uri] => verwaltung-und-politik/gremien/jugendbeirat/testunterseite
    [url] => /en/verwaltung-und-politik/gremien/jugendbeirat/testunterseite
    [siblings] => Kirby\Cms\Pages Object
        (
            [0] => verwaltung-und-politik/gremien/jugendbeirat/testunterseite
        )

)

See How to bootstrap Kirby in a given environment from CLI script - #12 by bvdputte

There might be a better way, need to check

Edit: see docs GitHub - getkirby/cli: Kirby Command Line Interface

Thank, you for pointing me in the right direction.
We actually have already set the url in the config but we relied on env(APP_HOST) to get it from our envs. the env helper seems to not be available but as soon as I w´swapped it with the native getenv from PHP it was working.