Skip to content

Resolve API URL for Codespaces port forwarding#18

Merged
sis0k0 merged 2 commits into
mainfrom
fix-codespaces-api-url
Jul 25, 2026
Merged

Resolve API URL for Codespaces port forwarding#18
sis0k0 merged 2 commits into
mainfrom
fix-codespaces-api-url

Conversation

@sis0k0

@sis0k0 sis0k0 commented Jul 25, 2026

Copy link
Copy Markdown
Member

Problem

In Codespaces, creating an employee fails:

POST https://…-4200.app.github.dev:5300/employees net::ERR_ADDRESS_UNREACHABLE

Root cause

ApiConfigService built the API base URL as ${window.location.hostname}:5300. In Codespaces the client host is …-4200.app.github.dev, so this produced …-4200.app.github.dev:5300. Codespaces doesn't expose ports as :port on the same host — each forwarded port is a separate subdomain (…-5300.app.github.dev) served over 443. The host:5300 URL therefore resolves to nothing.

Fix

When the host ends with .app.github.dev, swap the port segment (-4200-5300) and use the default (443) port; keep ${hostname}:5300 for local development.

if (hostname.endsWith('.app.github.dev')) {
  const apiHost = hostname.replace(/-\d+\.app\.github\.dev$/, '-5300.app.github.dev');
  return `${protocol}//${apiHost}`;
}
return `${protocol}//${hostname}:5300`;

Verification

  • ng build passes.
  • Transform check: …-4200.app.github.devhttps://…-5300.app.github.dev; localhosthttp://localhost:5300.
  • The API port (5300) is already made public by .devcontainer/portSetup.sh, and the server enables permissive CORS.

GitHub Codespaces forwards each port as its own subdomain (e.g.
name-5300.app.github.dev) served over 443, not as host:port. The client
built the API URL as `${hostname}:5300`, producing
name-4200.app.github.dev:5300, which is unreachable (ERR_ADDRESS_UNREACHABLE).

Move the URL resolution into a small pure helper (resolveApiBaseUrl in
api-url.ts) that transparently rewrites the forwarded-port host, so the
service just asks for a base URL and the port-forwarding detail stays
encapsulated. Local host:5300 behavior is unchanged.
@sis0k0
sis0k0 force-pushed the fix-codespaces-api-url branch 2 times, most recently from 04a7d93 to d24be04 Compare July 25, 2026 07:13
@sis0k0
sis0k0 force-pushed the fix-codespaces-api-url branch from d24be04 to 30a60f1 Compare July 25, 2026 07:28
@sis0k0
sis0k0 merged commit c63eb9a into main Jul 25, 2026
3 checks passed
@sis0k0
sis0k0 deleted the fix-codespaces-api-url branch July 25, 2026 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant