fix: replace Bun.serve with Node.js http module in auth-server#19
Closed
NikolayS wants to merge 4 commits into
Closed
fix: replace Bun.serve with Node.js http module in auth-server#19NikolayS wants to merge 4 commits into
NikolayS wants to merge 4 commits into
Conversation
The auth command was failing with "Bun is not defined" because auth-server.ts used Bun.serve() which is a Bun-specific API that doesn't exist when the code is compiled to run on Node.js. Replaced with Node.js native http.createServer() which works in both Bun and Node.js environments.
Contributor
Author
|
@cursor review |
|
You have run out of free Bugbot PR reviews for this billing cycle. This will reset on January 16. To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial. |
Contributor
Author
|
@cursor review |
Contributor
Author
|
@claude reivew |
- Add `ready` promise to CallbackServer interface that resolves when server is actually listening, fixing race condition where getPort() could return 0 before server started - Add error handler for server 'error' event to properly handle EADDRINUSE and other binding errors instead of silent failures - Update postgres-ai.ts to await ready promise instead of fragile 100ms setTimeout workaround
- Make stopServer() fully idempotent by clearing timeout on manual stop - Use 127.0.0.1 consistently in redirect URI to match server bind address (fixes potential IPv6 issues on dual-stack hosts where localhost may resolve to ::1 while server only binds to 127.0.0.1)
Contributor
Author
|
@cursor review again |
The test was timing out at 5s in CI. Increased to 15s to account for slower CI environments spinning up temporary PostgreSQL instances.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
postgresai authcommand failing with "Bun is not defined" error after the Node.js to Bun migrationBun.serve()API with Node.js nativehttp.createServer()incli/lib/auth-server.tsProblem
After the CLI migration to Bun (commit 1b1425a), the
authcommand broke completely:❯ postgresai auth Starting authentication flow... Starting local callback server... Authentication error: Bun is not definedRoot cause: The
auth-server.tsfile usedBun.serve()which is a Bun-specific API. Since the CLI is compiled withbun build --target node, theBunglobal doesn't exist at runtime.Solution
Replaced the Bun.serve() implementation with Node.js native http.createServer():
http.createServer()callback patternserverInstance.stop()toserverInstance.close()ReturnType<typeof Bun.serve>tohttp.ServergetServerPort()helper functionTesting
All CLI command groups verified working:
--version,help,prepare-db)mon(17 subcommands)auth(login,show-key,remove-key)issues(list,view,post_comment)mcp(start,install)OAuth flow now works correctly:
Starting authentication flow... Starting local callback server... Callback server listening on port 36679 ✅ Initializing authentication session...https://gitlab.com/postgres-ai/postgres_ai/-/issues/69
Note
Migrates the OAuth callback server off Bun to ensure Node runtime compatibility and more reliable startup/teardown.
cli/lib/auth-server.tsusing Nodehttp.createServer()with explicitserver.close(), structured HTML responses, and CSRF/state validationready: Promise<number>to expose the actual bound port; caller now awaits readiness before constructingredirect_uriEADDRINUSE) and centralizes shutdown viastopServer()cli/bin/postgres-ai.tsto awaitcallbackServer.readyand usehttp://127.0.0.1:<port>/callback(avoid IPv6 issues)Written by Cursor Bugbot for commit 15eccaf. Configure here.