Skip to content

authentication should not hardcode port 3333 #11

@paperclover

Description

@paperclover

to reproduce, start a server on port 3333 before using polar CLI for the first time.

$ bun src/cli.ts  listen http://localhost:3333
✔ Select Environment …  Sandbox
46 |     }
47 |   }
48 |   let er;
49 |   if (args.length > 0)
50 |     er = args[0];
51 |     throw er;
                 ^
error: Failed to start server. Is port 3333 in use?
      at emitError (node:events:51:13)

you can work around this by stopping your server, running polar, then running your server afterwards

please never call .listen with a hardcoded port number. you can never be sure if something already running on the system. in particular, a port like 3333 is very common to collide. passing 0 as the port allows the operating system to select a free port, automatically.

-           httpServer?.listen(3333, () => {
+           httpServer?.listen(0, () => {
+               const address = httpServer?.address();
+               assert(address && typeof address === 'object'); // not a unix socket
+               const { port } = address;
+
+               // create a URL that redirects to the correct port
                open(authorizationUrl);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions