Skip to content
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

Move error overlay middleware into react-error-overlay #2216

Merged
merged 1 commit into from
May 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/react-dev-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ var getProcessForPort = require('react-dev-utils/getProcessForPort');
getProcessForPort(3000);
```

#### `launchEditor(fileName: string, lineNumber: number): void`

On macOS, tries to find a known running editor process and opens the file in it. It can also be explicitly configured by `REACT_EDITOR`, `VISUAL`, or `EDITOR` environment variables. For example, you can put `REACT_EDITOR=atom` in your `.env.local` file, and Create React App will respect that.

#### `openBrowser(url: string): boolean`

Attempts to open the browser with a given URL.<br>
Expand Down
23 changes: 23 additions & 0 deletions packages/react-error-overlay/middleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';

const launchEditor = require('react-dev-utils/launchEditor');

module.exports = function createLaunchEditorMiddleware() {
return function launchEditorMiddleware(req, res, next) {
// Keep this in sync with react-error-overlay
if (req.url.startsWith('/__open-stack-frame-in-editor')) {
launchEditor(req.query.fileName, req.query.lineNumber);
res.end();
} else {
next();
}
};
};
3 changes: 2 additions & 1 deletion packages/react-error-overlay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
],
"author": "Joe Haddad <timer150@gmail.com>",
"files": [
"lib/"
"lib/",
"middleware.js"
],
"dependencies": {
"anser": "1.2.5",
Expand Down
1 change: 1 addition & 0 deletions packages/react-error-overlay/src/components/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ function createFrame(
.indexOf(' ') !== -1;
if (!isInternalWebpackBootstrapCode) {
onSourceClick = () => {
// Keep this in sync with react-error-overlay/middleware.js
fetch(
'/__open-stack-frame-in-editor?fileName=' +
window.encodeURIComponent(sourceFileName) +
Expand Down
13 changes: 3 additions & 10 deletions packages/react-scripts/config/webpackDevServer.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// @remove-on-eject-end
'use strict';

const launchEditor = require('react-dev-utils/launchEditor');
const errorOverlayMiddleware = require('react-error-overlay/middleware');
const config = require('./webpack.config.dev');
const paths = require('./paths');

Expand Down Expand Up @@ -70,15 +70,8 @@ module.exports = function(proxy, allowedHost) {
public: allowedHost,
proxy,
setup(app) {
// This lets us open files from the crash overlay.
app.use(function launchEditorMiddleware(req, res, next) {
if (req.url.startsWith('/__open-stack-frame-in-editor')) {
launchEditor(req.query.fileName, req.query.lineNumber);
res.end();
} else {
next();
}
});
// This lets us open files from the runtime error overlay.
app.use(errorOverlayMiddleware());
},
};
};