Skip to content

Commit

Permalink
Update /open-debugger to try first target when unspecified (facebook#…
Browse files Browse the repository at this point in the history
…39255)

Summary:

Changelog: [Internal]

Reviewed By: motiz88

Differential Revision: D48873336
  • Loading branch information
Alex Hunt authored and facebook-github-bot committed Sep 4, 2023
1 parent 83885f1 commit 87c6798
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
22 changes: 9 additions & 13 deletions packages/dev-middleware/src/middleware/openDebuggerMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -79,7 +76,6 @@ export default function openDebuggerMiddleware({
}

try {
logger?.info('Launching JS debugger...');
await debuggerInstances.get(appId)?.kill();
debuggerInstances.set(
appId,
Expand Down
2 changes: 1 addition & 1 deletion packages/dev-middleware/src/types/EventReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 87c6798

Please sign in to comment.