$ npm install @react-native/dev-middleware
Dev server middleware supporting core React Native development features. This package is preconfigured in all React Native projects.
Middleware can be attached to a dev server (e.g. Metro) using the createDevMiddleware
API.
import { createDevMiddleware } from '@react-native/dev-middleware';
function myDevServerImpl(args) {
...
const {middleware, websocketEndpoints} = createDevMiddleware({
projectRoot: metroConfig.projectRoot,
serverBaseUrl: `http://${args.host}:${args.port}`,
logger,
});
await Metro.runServer(metroConfig, {
host: args.host,
...,
unstable_extraMiddleware: [
middleware,
// Optionally extend with additional HTTP middleware
],
websocketEndpoints: {
...websocketEndpoints,
// Optionally extend with additional WebSocket endpoints
},
});
}
@react-native/dev-middleware
is designed for integrators such as @expo/dev-server
and @react-native/community-cli-plugin
. It provides a common default implementation for core React Native dev server responsibilities.
We intend to keep this to a narrow set of functionality, based around:
DevMiddlewareAPI.middleware
These are exposed as a connect
middleware handler, assignable to Metro.runServer
or other compatible HTTP servers.
/json/list
, /json
(CDP)Returns the list of available WebSocket targets for all connected React Native app sessions.
/json/version
(CDP)Returns version metadata used by Chrome DevTools.
/debugger-frontend
Subpaths of this endpoint are reserved to serve the JavaScript debugger frontend.
/open-debugger
Open the JavaScript debugger for a given CDP target (direct Hermes debugging).
curl -X POST 'http://localhost:8081/open-debugger?appId=com.meta.RNTester'
DevMiddlewareAPI.websocketEndpoints
/inspector/device
WebSocket handler for registering device connections.
/inspector/debug
WebSocket handler that proxies CDP messages to/from the corresponding device.
Changes to this package can be made locally and tested against the rn-tester
app, per the Contributing guide. During development, this package is automatically run from source with no build step.
© 2010 - cnpmjs.org x YWFE | Home | YWFE