Skip to content

Commit

Permalink
Click to view source from error overlay (facebook#2141)
Browse files Browse the repository at this point in the history
* Click to view source

* Update package.json

* Update package.json

* Fix lint
  • Loading branch information
gaearon committed May 14, 2017
1 parent a60dced commit 87d3d75
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions scripts/utils/addWebpackMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const chalk = require('chalk');
const dns = require('dns');
const historyApiFallback = require('connect-history-api-fallback');
const httpProxyMiddleware = require('http-proxy-middleware');
const launchEditor = require('react-dev-utils/launchEditor');
const url = require('url');
const paths = require('../../config/paths');

Expand Down Expand Up @@ -145,10 +146,23 @@ function registerProxy(devServer, _proxy) {
});
}

// This is used by the crash overlay.
function launchEditorMiddleware() {
return function(req, res, next) {
if (req.url.startsWith('/__open-stack-frame-in-editor')) {
launchEditor(req.query.fileName, req.query.lineNumber);
res.end();
} else {
next();
}
};
}

module.exports = function addWebpackMiddleware(devServer) {
// `proxy` lets you to specify a fallback server during development.
// Every unrecognized request will be forwarded to it.
const proxy = require(paths.appPackageJson).proxy;
devServer.use(launchEditorMiddleware());
devServer.use(
historyApiFallback({
// Paths with dots should still use the history fallback.
Expand Down

0 comments on commit 87d3d75

Please sign in to comment.