Skip to content

fix(api): accept GridTracker's auth POST and path-segment-key station_info#206

Merged
patrickrb merged 1 commit into
mainfrom
fix/gridtracker-post-and-path-key
May 11, 2026
Merged

fix(api): accept GridTracker's auth POST and path-segment-key station_info#206
patrickrb merged 1 commit into
mainfrom
fix/gridtracker-post-and-path-key

Conversation

@patrickrb
Copy link
Copy Markdown
Owner

Summary

Fixes two real-world mismatches between GridTracker's Cloudlog client and what nextlog implemented. Verified by inspecting GT's app.asar (src/renderer/lib/adif.js) — functions CloudlogTest, CloudlogTestApiKey, CloudlogGetProfiles, CloudlogFillProfiles.

Problem 1: /api/auth/[key] rejected POST

GT POSTs to {URL}/index.php/api/auth/{KEY} despite the key being in the path. Our handler only exported GET, so Vercel returned 405 Method Not Allowed with Content-Length: 0. GT's response parser saw an empty buffer and rendered "Invalid Response" — the user's stall at "Testing API Key" followed by "Invalid Response".

Fix: alias GET and POST to a single handler. Also added an OPTIONS handler for CORS preflight. This matches wavelog/CodeIgniter behavior, where the same controller function answers any HTTP method.

Problem 2: /api/station_info/[key] didn't exist

After auth succeeds, GT immediately fetches the station profile list at {URL}/index.php/api/station_info/{KEY} (key in path, empty body). Our existing /api/station_info only read the key from the JSON body, so the dynamic path 404'd → empty buffer → GT overwrote "OK" with "Invalid Response".

Fix: new /api/station_info/[key]/route.ts dynamic route that handles both GET and POST. Existing /api/station_info (body form) is preserved unchanged — both call into a shared stationInfoResponse(key) helper in src/lib/station-info.ts so they return byte-identical JSON.

What's the same as before

  • /api/station_info (body form, no path segment) — wire-compatible, no behavior change
  • /api/auth/[key] for GET requests — same XML response as before
  • All other endpoints

Test plan

  • npm run typecheck clean
  • npm run lint clean
  • POST /api/auth/<key> → 200 XML <status>Valid</status><rights>rw</rights> (was 405)
  • POST /api/station_info/<key> → 200 JSON station array
  • POST /api/station_info (body form) → 200 JSON station array (regression check, unchanged)
  • After deploy: GridTracker's Test button shows "OK" and populates the station profile dropdown

How the bug was found

User reported GT stuck at "Testing API Key" then flipping to "Invalid Response". GT's renderer log (%APPDATA%\GridTracker2\logs\main.log) showed Unexpected token '<' JSON parse errors — confirming GT was getting HTML/empty body instead of expected response. Extracted GT's app.asar, read the actual CloudlogTest / CloudlogGetProfiles functions, found the two URL forms GT uses.

🤖 Generated with Claude Code

… shape

GridTracker's Cloudlog client (inspected via app.asar src) sends
requests that don't quite match what nextlog implemented:

  1. POST {URL}/index.php/api/auth/{KEY}       (not GET)
  2. POST {URL}/index.php/api/station_info/{KEY}   (key in path, no body)

Our /api/auth/[key] only exported GET → Vercel returned 405 Method Not
Allowed with an empty body → GT logged "Invalid Response" and stalled
at "Testing API Key". Our /api/station_info only accepted the key in
the JSON body, so /api/station_info/{KEY} 404'd → after auth's "OK"
the profile-fill response was empty → GT overwrote "OK" with the same
"Invalid Response" message.

This commit:

- /api/auth/[key]: alias GET and POST to one handler; add an OPTIONS
  handler for CORS preflight. Matches wavelog/CodeIgniter behavior
  where controllers respond to any HTTP method.
- /api/station_info/[key]: new dynamic route, POST + GET both supported
- /api/station_info (body form) preserved as-is, no breaking change
- Extract shared lookup logic into src/lib/station-info.ts so both
  routes return identical wavelog-shape JSON

Verified GT's full flow by reading
  C:\Users\burns\AppData\Local\Programs\GridTracker2\resources\app.asar
  src/renderer/lib/adif.js — functions CloudlogTest,
  CloudlogGetProfiles, CloudlogTestApiKey, CloudlogFillProfiles.

After this lands, GT's Test button should show "OK" and populate the
station profile dropdown.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nodelog Ready Ready Preview, Comment May 11, 2026 7:34pm

Request Review

@patrickrb patrickrb merged commit 5ffe12b into main May 11, 2026
7 checks passed
@patrickrb patrickrb deleted the fix/gridtracker-post-and-path-key branch May 11, 2026 19:36
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