14

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?

Nathan
  • 1,451
  • 1
  • 15
  • 28

2 Answers2

13

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.

jackotonye
  • 3,537
  • 23
  • 31
Nathan
  • 1,451
  • 1
  • 15
  • 28
7

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

Nel
  • 454
  • 5
  • 14