Hack to fix #49 until we can move to express.
This commit is contained in:
parent
d3f1f6868c
commit
6cfbe60031
@ -192,6 +192,26 @@ PeerServer.prototype._initializeHTTP = function() {
|
||||
this._app.use(restify.queryParser());
|
||||
this._app.use(util.allowCrossDomain);
|
||||
|
||||
/** Hack from https://github.com/mcavage/node-restify/issues/284, until we switch to express */
|
||||
function unknownMethodHandler(req, res) {
|
||||
if (req.method.toLowerCase() === 'options') {
|
||||
var allowHeaders = ['Accept', 'Accept-Version', 'Content-Type', 'Api-Version'];
|
||||
|
||||
if (res.methods.indexOf('OPTIONS') === -1) res.methods.push('OPTIONS');
|
||||
|
||||
res.header('Access-Control-Allow-Credentials', true);
|
||||
res.header('Access-Control-Allow-Headers', allowHeaders.join(', '));
|
||||
res.header('Access-Control-Allow-Methods', res.methods.join(', '));
|
||||
res.header('Access-Control-Allow-Origin', req.headers.origin);
|
||||
|
||||
return res.send(204);
|
||||
} else {
|
||||
return res.send(new restify.MethodNotAllowedError());
|
||||
}
|
||||
}
|
||||
|
||||
this._app.on('MethodNotAllowed', unknownMethodHandler);
|
||||
|
||||
// Retrieve guaranteed random ID.
|
||||
this._app.get(this._options.path + ':key/id', function(req, res, next) {
|
||||
res.contentType = 'text/html';
|
||||
|
Loading…
x
Reference in New Issue
Block a user