Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I run a web server in a GitHub Codespace?

Part of my development process involves using Mocha and Chai tests. I have a page in my test folder that loads all the code and tests, and I can start up a local node script that runs a simple local server, visit that page on http://localhost:8080/blahblahblah.html, and see the test results.

GitHub recently announced Codespaces and I signed up for the beta. If I start developing in a Codespace, I know there's a terminal there. If I run my testing server in that Codespace, how would I see the test results? Is it even possible to connect to the server in the container from outside? What would replace the URL I show above?

like image 842
Nathan Avatar asked Dec 03 '25 13:12

Nathan


2 Answers

Found the answer here:

https://docs.github.com/en/codespaces/developing-in-codespaces/forwarding-ports-in-your-codespace

It's actually pretty surprising. You just have your web server app print a localhost URL to the console, and the Codespace automatically converts that to a clickable URL with the appropriate port-forwarding. Kind of a huge surprise, but also pretty cool.

Just tested and this works.

like image 136
Nathan Avatar answered Dec 06 '25 11:12

Nathan


When an application running inside a codespace outputs a port to the console, Codespaces detects the localhost URL pattern and automatically forwards those ports. You can click on the URL in the terminal to open it in a browser. For example, if an application outputs http://127.0.0.1:3000 or http://localhost:3000 to the console, the log would automatically convert the output to a clickable URL for port 3000.

enter image description here

like image 40
Nel Avatar answered Dec 06 '25 11:12

Nel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!