Skip to content

Commit

Permalink
Merge pull request #144 from leonli/patch-for-http-proxy
Browse files Browse the repository at this point in the history
Added the error handling to avoid http-party/node-http-proxy#527
  • Loading branch information
james-lee1989 committed Aug 27, 2015
2 parents 5fbafc2 + 6bb8b94 commit e76da1f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = function (config) {
singleRun: true,

frameworks: [ 'mocha' ],

files: [
'tests.webpack.js'
],
Expand Down
12 changes: 12 additions & 0 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ app.use('/api', (req, res) => {
proxy.web(req, res);
});

// added the error handling to avoid https://github.com/nodejitsu/node-http-proxy/issues/527
proxy.on('error', (error, req, res) => {
let json;
console.log('proxy error', error);
if (!res.headersSent) {
res.writeHead(500, {'content-type': 'application/json'});
}

json = { error: 'proxy_error', reason: error.message };
res.end(JSON.stringify(json));
});

app.use((req, res) => {
if (__DEVELOPMENT__) {
// Do not cache webpack stats: the script file would change since
Expand Down

0 comments on commit e76da1f

Please sign in to comment.