Update /open-debugger to try first target when unspecified (#39255)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39255

Changelog: [Internal]

Reviewed By: motiz88

Differential Revision: D48873336

fbshipit-source-id: 8d3aac383de1cefa303a89fbfee9a23ce906a979
This commit is contained in:
Alex Hunt
2023-09-04 06:36:42 -07:00
committed by Facebook GitHub Bot
parent 054ab62be0
commit f688a2d4be
2 changed files with 10 additions and 14 deletions
@@ -50,19 +50,16 @@ export default function openDebuggerMiddleware({
const {query} = url.parse(req.url, true);
const {appId} = query;
if (typeof appId !== 'string') {
res.writeHead(400);
res.end();
eventReporter?.logEvent({
type: 'launch_debugger_frontend',
status: 'coded_error',
errorCode: 'MISSING_APP_ID',
});
return;
}
const targets = await queryInspectorTargets(getDevServerUrl(req));
const target = targets.find(_target => _target.description === appId);
let target;
if (typeof appId === 'string') {
logger?.info('Launching JS debugger...');
target = targets.find(_target => _target.description === appId);
} else {
logger?.info('Launching JS debugger for first available target...');
target = targets[0];
}
if (!target) {
res.writeHead(404);
@@ -79,7 +76,6 @@ export default function openDebuggerMiddleware({
}
try {
logger?.info('Launching JS debugger...');
await debuggerInstances.get(appId)?.kill();
debuggerInstances.set(
appId,
@@ -37,7 +37,7 @@ export type ReportableEvent =
...
| SuccessResult<{appId: string}>
| ErrorResult<mixed>
| CodedErrorResult<'MISSING_APP_ID' | 'NO_APPS_FOUND'>,
| CodedErrorResult<'NO_APPS_FOUND'>,
}
| {
type: 'connect_debugger_frontend',