-
Notifications
You must be signed in to change notification settings - Fork 909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
breaking: Drop browser helpers from cli-tools, simplify middleware #2588
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import type {IncomingMessage, ServerResponse} from 'http'; | ||
|
||
import {json} from 'body-parser'; | ||
import connect from 'connect'; | ||
import {launchEditor} from '@react-native-community/cli-tools'; | ||
|
||
type Options = { | ||
watchFolders: ReadonlyArray<string>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @szymonrybczak Relevant to your other comment, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, thanks for explanation! |
||
}; | ||
|
||
/** | ||
* Open a stack frame in the user's text editor. | ||
*/ | ||
export default function openStackFrameMiddleware(_: Options) { | ||
const handler = ( | ||
req: IncomingMessage & { | ||
// Populated by body-parser | ||
body?: Object; | ||
}, | ||
res: ServerResponse, | ||
next: (err?: Error) => void, | ||
) => { | ||
if (req.method === 'POST') { | ||
if (req.body == null) { | ||
res.writeHead(400); | ||
res.end('Missing request body'); | ||
return; | ||
} | ||
|
||
const frame = req.body as { | ||
file: string; | ||
lineNumber: number; | ||
}; | ||
|
||
launchEditor(frame.file, frame.lineNumber); | ||
|
||
res.writeHead(200); | ||
res.end(); | ||
} | ||
|
||
next(); | ||
}; | ||
|
||
return connect().use(json()).use(handler); | ||
} |
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fun 😄. We have a fix to make around this in Metro. See the original CLI PR: #1147.
I’ve actioned an initial change in React Native — also required for the substitution of
body-parser
for the endpoints in this PR:Once removed, we can simplify further and apply
.use(json())
against this entire middleware stack.