Skip to content

fix(api): decide /api or /webrest at login only - #272

Merged
edospadoni merged 5 commits into
mainfrom
fix-webrest-fallback
Nov 25, 2026
Merged

edospadoni merged 5 commits into
mainfrom
fix-webrest-fallback

Conversation

@edospadoni

@edospadoni edospadoni commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

NethVoice 1.9 will stop publishing the legacy CTI server on /webrest and /socket.io (nethesis/ns8-nethvoice#1308): every client must use the middleware on /api and /api/ws. This fix must ship before that, so users are not locked out.

NethLink could get stuck on /webrest: any 404 from an /api endpoint (or a network error on login) switched the client to /webrest and saved it in the account, so later sessions kept using it. On NethVoice 1.9 those accounts would stay broken.

  • The base path is decided at login only: /api/login is always tried first, /webrest is used only when /api/login itself answers 404 or 405 (a PBX without the middleware). Other errors are returned to the caller and never change the path; a network error is reported as a lost connection instead of wrong credentials.
  • A restored session follows its token: a JWT uses /api, only a legacy hash token uses /webrest. The apiBasePath saved by older releases is ignored and no longer written, so stuck accounts recover on the next start.
  • Update @nethesis/phone-island to v1.1.9 (fix(api): probe the API mode on every init nethesis/phone-island#322): older versions saved the API mode they probed in localStorage and never probed again, so a stale legacy mode kept them on /webrest and /socket.io. The new version probes on every start.

Tested with npm run typecheck and a harness around useNethVoiceAPI with a mocked HTTP client: new PBX, stored /webrest with a JWT, 404 on a non-login endpoint (no switch), network error and 503 on /api/login (no switch), legacy PBX (/api/login 404, hash login on /webrest), legacy account restored, PBX upgraded after a legacy login.

NethServer/dev#8358

@github-actions

Copy link
Copy Markdown

Automatic builds from https://github.com/NethServer/nethlink/actions/runs/45413057209.
Commit: fdefaa8

Name Platform Link
win-app.exe Windows (x64) Link
macos-app-x64.dmg MacOS (x64) Link
macos-app-arm64.dmg MacOS (arm64) Link
linux-app.AppImage Linux (x64) Link

Any 404 from an /api endpoint, or a network error on login, switched
the client to /webrest and saved it in the account, so the next
sessions kept using /webrest. NethVoice 1.9 will stop publishing
/webrest and /socket.io, and such accounts would stay broken.

Probe /api/login first on every login and use /webrest only when it
answers 404, that is a PBX without the middleware. Other errors are
returned to the caller and never change the path. A restored session
follows its token: JWT uses /api, only a legacy hash token uses
/webrest, so a stored apiBasePath of /webrest is ignored.

Phone Island saves the API mode it probes in localStorage and never
probes again: set it from the login result, so a stale legacy mode
does not keep it on /webrest and /socket.io.

Refs NethServer/dev#8358
@github-actions

Copy link
Copy Markdown

Automatic builds from https://github.com/NethServer/nethlink/actions/runs/45414014275.
Commit: 561da68

Name Platform Link
win-app.exe Windows (x64) Link
macos-app-x64.dmg MacOS (x64) Link
macos-app-arm64.dmg MacOS (arm64) Link
linux-app.AppImage Linux (x64) Link

@tonyco97 tonyco97 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI green on all 4 targets. Traced auto-login: non-JWT accounts go through Authentication.login, which now probes /api/login first, so legacy accounts move to /api after a PBX upgrade 👍. Main point is how this interacts with nethesis/phone-island#322; the rest are questions and nits.

Two nits on lines outside the diff:

  • 🔵 nit: AccountController.ts:131: the comment "follows account settings/fallback logic" is out of date: there is no fallback anymore and the stored apiBasePath is ignored.
  • 🔵 nit: apiBasePath is still written in 3 places in useNethVoiceAPI.ts but never read. Keep it only if it's meant for downgrade compatibility; otherwise drop it from Account.

Comment thread src/shared/useNethVoiceAPI.ts Resolved
Comment thread src/shared/useNethVoiceAPI.ts Resolved
Treat a 405 on /api/login like a 404, as a PBX without the middleware
may answer either, and report a network error as a lost connection
instead of wrong credentials.

Drop apiBasePath from the account: nothing reads it anymore. Update
the comments on the Phone Island API mode and on the token check.
@edospadoni

Copy link
Copy Markdown
Member Author

Also fixed the two notes outside the diff in 138b505: the comment at AccountController.ts:131 now says the path follows the saved token type, and apiBasePath is gone from Account and from the three writes. Nothing read it, and a downgraded NethLink starts from /api anyway when the field is missing.

@github-actions

Copy link
Copy Markdown

Automatic builds from https://github.com/NethServer/nethlink/actions/runs/45573309719.
Commit: 138b505

Name Platform Link
win-app.exe Windows (x64) Link
macos-app-x64.dmg MacOS (x64) Link
macos-app-arm64.dmg MacOS (arm64) Link
linux-app.AppImage Linux (x64) Link

@edospadoni
edospadoni requested a review from tonyco97 November 25, 2026 08:14

@tonyco97 tonyco97 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, 405 handling, the comment updates and the apiBasePath removal look good, CI green. One regression from the new network-error branch below.

Comment thread src/shared/useNethVoiceAPI.ts Resolved
The plain errors thrown during login, such as a user without a NethLink
extension, have no response either and were reported as a lost
connection. Check them first and match only failed axios requests.
@edospadoni
edospadoni requested a review from tonyco97 November 25, 2026 08:36
@github-actions

Copy link
Copy Markdown

Automatic builds from https://github.com/NethServer/nethlink/actions/runs/45577792038.
Commit: 1254081

Name Platform Link
win-app.exe Windows (x64) Link
macos-app-x64.dmg MacOS (x64) Link
macos-app-arm64.dmg MacOS (arm64) Link
linux-app.AppImage Linux (x64) Link

@tonyco97 tonyco97 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All review points addressed in 1254081, thanks. Re-checked the login error mapping: plain errors thrown inside the try (User not authorized for NethLink, No token received) no longer end up as "Network connection lost", only failed axios requests and 404 do. CI green on all 4 targets.

Phone Island 1.1.9 probes the API mode on every start instead of
keeping the mode saved by older versions.
Phone Island 1.1.9 probes the API mode on every start, so NethLink no
longer needs to overwrite the mode saved by older versions.
@edospadoni

Copy link
Copy Markdown
Member Author

phone-island v1.1.9 is released, so this PR now bundles it (d485691) and drops the localStorage write in usePhoneIsland.ts (84113df): there is nothing left to clean up after the merge.

@edospadoni
edospadoni requested a review from tonyco97 November 25, 2026 09:05
@github-actions

Copy link
Copy Markdown

Automatic builds from https://github.com/NethServer/nethlink/actions/runs/45582123273.
Commit: 84113df

Name Platform Link
win-app.exe Windows (x64) Link
macos-app-x64.dmg MacOS (x64) Link
macos-app-arm64.dmg MacOS (arm64) Link
linux-app.AppImage Linux (x64) Link

@edospadoni
edospadoni merged commit 8d96888 into main Nov 25, 2026
4 checks passed
@edospadoni
edospadoni deleted the fix-webrest-fallback branch November 25, 2026 09:32
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.

2 participants