Skip to content

Commit 8d3a216

Browse files
committed
Add JSON error response, include supported methods
1 parent 6d610d3 commit 8d3a216

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

proxy.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,19 @@ exports.proxy = function(req, res, options, buffer){
6969

7070
res.writeHead(502, {
7171
'Content-Type': 'text/plain',
72-
'Access-Control-Allow-Origin': '*'
72+
'Access-Control-Allow-Origin': '*',
73+
'Access-Control-Allow-Methods' : 'OPTIONS, TRACE, GET, HEAD, POST, PUT'
7374
});
7475

7576
if (req.method !== 'HEAD') {
7677

7778
//
7879
// This NODE_ENV=production behavior is mimics Express and
7980
// Connect.
80-
if (process.env.NODE_ENV === 'production') {
81-
res.write('Internal Server Error');
82-
}
83-
else {
84-
res.write('An error has occurred: ' + JSON.stringify(err));
85-
}
81+
//if (process.env.NODE_ENV === 'production') {
82+
// res.write('Internal Server Error');
83+
//}
84+
res.write(JSON.stringify({error:err}));
8685
}
8786

8887
try { res.end(); }
@@ -168,6 +167,7 @@ exports.proxy = function(req, res, options, buffer){
168167
Object.keys(_res.headers).forEach(function (key) {
169168
res.setHeader(key, _res.headers[key]);
170169
});
170+
res.setHeader("Access-Control-Allow-Methods", 'OPTIONS, TRACE, GET, HEAD, POST, PUT');
171171
res.setHeader("Access-Control-Allow-Origin", "*");
172172

173173
res.writeHead(_res.statusCode);

0 commit comments

Comments
 (0)