-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Manual proxy routes are now persistent and proxies will fail graceful…
…ly if port is in use
- Loading branch information
Hadrien Jouet
committed
Jan 27, 2013
1 parent
d889e89
commit b054cdb
Showing
4 changed files
with
109 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
var BaseModel = require('./_base').BaseModel, | ||
util = require('util'); | ||
|
||
var ProxyModel = function() { | ||
ProxyModel.super_.apply(this, arguments); | ||
}; | ||
|
||
util.inherits(ProxyModel, BaseModel); | ||
|
||
ProxyModel.prototype.createOrUpdate = function(source, target, callback) { | ||
var self = this; | ||
|
||
this.get({source: source}, function(err, result) { | ||
if (err) | ||
return callback(err); | ||
|
||
if (result.length == 1) | ||
self.edit(result[0]._id.toString(), {$set: {target: target}}, callback); | ||
else | ||
self.add({source: source, target: target}, callback); | ||
}); | ||
}; | ||
|
||
ProxyModel.prototype.deleteBy = function(filter, callback) { | ||
var self = this; | ||
|
||
this.get(filter, function(err, result) { | ||
if (err) | ||
return callback(err); | ||
|
||
if (result.length > 0) { | ||
result.forEach(function(route) { | ||
self.delete(route._id.toString(), function() {}); | ||
}); | ||
|
||
callback(null); | ||
} | ||
}); | ||
}; | ||
|
||
module.exports = new ProxyModel({collection: 'proxy'}); |