Skip to content

Commit

Permalink
Fix delayed shutdown after login (#864)
Browse files Browse the repository at this point in the history
fix: Shut down server faster during logins. Avoids long pause after login completes.
  • Loading branch information
sqrrrl committed Aug 9, 2021
1 parent 48e6fa3 commit 40e0b3d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
30 changes: 30 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"p-map": "^5.0.0",
"read-pkg-up": "^8.0.0",
"recursive-readdir": "^2.2.2",
"server-destroy": "^1.0.1",
"split-lines": "^3.0.0",
"strip-bom": "^5.0.0",
"ts2gas": "^4.0.0",
Expand All @@ -97,6 +98,7 @@
"@types/mocha": "^8.2.2",
"@types/node": "^12.20.15",
"@types/recursive-readdir": "^2.2.0",
"@types/server-destroy": "^1.0.1",
"@types/tmp": "^0.2.0",
"@types/wtfnode": "^0.7.0",
"chai": "^4.3.4",
Expand Down
4 changes: 3 additions & 1 deletion src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {ReadonlyDeep} from 'type-fest';

import type {ClaspToken} from './dotfile';
import type {ClaspCredentials} from './utils';
import enableDestroy from 'server-destroy';

/**
* Authentication with Google's APIs.
Expand Down Expand Up @@ -217,6 +218,7 @@ const authorizeWithLocalhost = async (
// the server port needed to set up the Oauth2Client.
const server = await new Promise<Server>(resolve => {
const s = createServer();
enableDestroy(s);
s.listen(0, () => resolve(s));
});
const {port} = server.address() as AddressInfo;
Expand All @@ -240,7 +242,7 @@ const authorizeWithLocalhost = async (
console.log(LOG.AUTHORIZE(authUrl));
(async () => await open(authUrl))();
});
server.close();
server.destroy();

return (await client.getToken(authCode)).tokens;
};
Expand Down

0 comments on commit 40e0b3d

Please sign in to comment.