From 132a20d5a7cb9986024a62ca3698ba69d4ced0c9 Mon Sep 17 00:00:00 2001 From: Lorenzo Blasa Date: Wed, 7 Jun 2023 07:39:56 -0700 Subject: [PATCH] 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 --- desktop/flipper-server/src/index.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/desktop/flipper-server/src/index.tsx b/desktop/flipper-server/src/index.tsx index 29d462d97..74c604b2b 100644 --- a/desktop/flipper-server/src/index.tsx +++ b/desktop/flipper-server/src/index.tsx @@ -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() {