Codespace port forwarding returns 404 after restart #201508
Replies: 4 comments
|
I've run into this before. Usually the issue is that when the codespace stops, the dev server shuts down, and when it restarts the port forwarding doesn't reconnect properly. Try these in order:
Most of the time the simple restart of the dev server does it. |
|
One extra distinction that helps here: a 404 usually means the forwarded URL is reaching something, but the application behind the forwarded port is not serving that route/path. If port forwarding itself were completely broken, I would expect connection refused, timeout, or an auth/visibility error rather than your app returning a 404. After a Codespace resumes, I would check it in this order: # 1. Is the dev server process actually running?
ps aux | grep -E "vite|next|node|python|rails|django" | grep -v grep
# 2. Is anything listening on the expected port?
ss -ltnp | grep :PORT
# or
lsof -i :PORT
# 3. Does the app answer from inside the codespace?
curl -i http://localhost:PORT/If If localhost works but the forwarded URL returns 404, then I would remove and re-add the forwarded port from the Ports tab, or set it explicitly in {
"forwardPorts": [3000],
"portsAttributes": {
"3000": {
"label": "web app",
"onAutoForward": "openBrowser"
}
}
}GitHub documents automatic port forwarding here: https://docs.github.com/en/codespaces/developing-in-a-codespace/forwarding-ports-in-your-codespace#automatically-forwarding-a-port One more common cause after resume: some dev servers bind only to npm run dev -- --host 0.0.0.0 --port 3000So the quick split is:
|
This comment was marked as spam.
This comment was marked as spam.
|
I just had the same problem for the first time. I never saw this during the last two years or so with exactly the same setup. Let's see if it happens again. |
Uh oh!
There was an error while loading. Please reload this page.
🏷️ Discussion Type
Question
Body
When my Codespace is being timed out and started again my forwarded port just returns 404. Despite working before the time out and no changes made to the branch in the codespace.

All reactions