This repository has been archived by the owner on Jan 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dev-server][xdl] suppress remote debugging EISDIR error (#3889)
# Why facebook/react-native#28844 # How prepending a middleware in metro and return 404 for `/debugger-ui/*.map` requests # Test Plan initialize a sdk43 project. launch app, enable remote debugging and open inspector. seeing if there are EISDIR errors.
- Loading branch information
Showing
6 changed files
with
63 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
packages/dev-server/src/middleware/replaceMiddlewareWith.ts
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
packages/dev-server/src/middleware/suppressErrorMiddleware.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { IncomingMessage, ServerResponse } from 'http'; | ||
|
||
// Middleware to suppress `EISDIR` error when opening javascript inspector in remote debugging. | ||
// A workaround for https://github.com/facebook/react-native/issues/28844 | ||
// The root cause is that metro cannot serve sourcemap requests for /debugger-ui/ | ||
export function suppressRemoteDebuggingErrorMiddleware( | ||
req: IncomingMessage, | ||
res: ServerResponse, | ||
next: (err?: Error) => void | ||
) { | ||
if (req.url?.match(/\/debugger-ui\/.+\.map$/)) { | ||
res.writeHead(404); | ||
res.end('Sourcemap for /debugger-ui/ is not supported.'); | ||
return; | ||
} | ||
next(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { Server as ConnectServer, HandleFunction } from 'connect'; | ||
|
||
/** | ||
* Prepends a `middleware` to current server middleware stack. | ||
* | ||
* @param app connect app server instance | ||
* @param middleware target middleware to be prepended | ||
*/ | ||
export function prependMiddleware(app: ConnectServer, middleware: HandleFunction) { | ||
app.use(middleware); | ||
app.stack.unshift(app.stack.pop()!); | ||
} | ||
|
||
/** | ||
* Replaces source middleware with a new middlware in connect app | ||
* | ||
* @param app connect app server instance | ||
* @param sourceMiddleware source middlware to be matched and replaces | ||
* @param targetMiddleware new middlware | ||
*/ | ||
export function replaceMiddlewareWith( | ||
app: ConnectServer, | ||
sourceMiddleware: HandleFunction, | ||
targetMiddleware: HandleFunction | ||
) { | ||
const item = app.stack.find(middleware => middleware.handle === sourceMiddleware); | ||
if (item) { | ||
item.handle = targetMiddleware; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters