URL resolving on Github Codespaces

Hi there!

I am developing Kirby locally with Docker which works fine, the dev environment can be viewed through local host and i am exposing port 80 and 443. Deployed to the server it is not inside a docker environment anymore.

Now i started playing around with Codespaces a lot, which is great, especially with the already in place docker setup, i can just run Kirby on codespaces, code in the browser, see the website and all that. There is just on issue i can’t quite figure out. All the url functions give me localhost back but the Codespaces domain ist something like *.apps.codespaces.githubusercontent.com.

Can someone point me to the right direction on how to solve this? I found this other issue but i am not sure if that is the right direction.

I’m not familiar with Codespace’s environment or setup, but you should be able to override the URL Index in your index.php (where your Kirby object is created and rendered).

Something like:

$kirby = new Kirby([
    'urls' => [
        'index' => url::scheme() . '://' . url::host(),
    ],
]);
echo $kirby->render();

There’s probably a more “reliable” $_SERVER variable you can use, but that probably depends on how the Codespaces environment is configured (and might differ between Nginx and Apache). But, I’ve used the code similar to the snippet above in the past.

Thanks for your reply!

I think this is somewhat the default behaviour of Kirby, right? Figuring out the current host and setting that url respectively. I tried that as well though but with no good results. (Configuration | Kirby)

I also think this works as expected, the current url would be localhost. Running that docker environment on my local machine pulls up localhost just fine.
I’m not very good at server things so … just trying around and to understand how I can solve that.

I am also portforwarding and is just now found this one: Kirby drops forwarded port · Issue #8 · getkirby-v2/toolkit · GitHub

I probably have to somehow tell only the Codespaces environment that I am forwarding ports so Kirby can respect that or actually even know about it.

Not sure if I should be embarrassed or something but this in the Kirby config fixed it: 'url' => '/'

:smiley:

1 Like