Token read from invalid path

Summary:
^

Token is no longer in the static directory. Also, we can now use a shared utility.

Reviewed By: aigoncharov

Differential Revision: D46516296

fbshipit-source-id: c38d024061653ac8b3fb587c8e3ad83dba0b151d
This commit is contained in:
Lorenzo Blasa
2023-06-07 07:39:56 -07:00
committed by Facebook GitHub Bot
parent 7dc978c3d3
commit 132a20d5a7

View File

@@ -22,6 +22,7 @@ import {initCompanionEnv} from 'flipper-server-companion';
import {
checkPortInUse,
getEnvironmentInfo,
hasAuthToken,
startFlipperServer,
startServer,
} from 'flipper-server-core';
@@ -132,16 +133,19 @@ async function connectToRunningServer(url: URL) {
async function shutdown() {
console.info('[flipper-server] Attempt to shutdown.');
const tokenPath = path.resolve(staticPath, 'auth.token');
const token = await fs.readFile(tokenPath, 'utf-8');
let token: string | undefined;
if (await hasAuthToken()) {
token = await getAuthToken();
}
const searchParams = new URLSearchParams({token: token ?? ''});
const searchParams = new URLSearchParams(token ? {token} : {});
const url = new URL(`ws://localhost:${argv.port}?${searchParams}`);
const server = await connectToRunningServer(url);
await server.exec('shutdown').catch(() => {
/** shutdown will ultimately make this request fail, ignore error. */
console.info('[flipper-server] Shutdown may have succeeded');
});
server.close();
}
async function start() {