Support per-model and per-handler remoting options
Allow the developer to pass custom `remoting` options via Model settings, e.g. PersistedModel.extend( 'MyModel', { name: String }, { remoting: { normalizeHttpPath: true } }); Also add `options` arg to `app.handler`, this object is passed directly to strong-remoting handler.
This commit is contained in:
parent
2384c9d841
commit
568c8662b4
|
@ -263,14 +263,14 @@ app.remoteObjects = function () {
|
||||||
* @triggers `mounted` events on shared class constructors (models)
|
* @triggers `mounted` events on shared class constructors (models)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
app.handler = function (type) {
|
app.handler = function (type, options) {
|
||||||
var handlers = this._handlers || (this._handlers = {});
|
var handlers = this._handlers || (this._handlers = {});
|
||||||
if(handlers[type]) {
|
if(handlers[type]) {
|
||||||
return handlers[type];
|
return handlers[type];
|
||||||
}
|
}
|
||||||
|
|
||||||
var remotes = this.remotes();
|
var remotes = this.remotes();
|
||||||
var handler = this._handlers[type] = remotes.handler(type);
|
var handler = this._handlers[type] = remotes.handler(type, options);
|
||||||
|
|
||||||
remotes.classes().forEach(function(sharedClass) {
|
remotes.classes().forEach(function(sharedClass) {
|
||||||
sharedClass.ctor.emit('mounted', app, sharedClass, remotes);
|
sharedClass.ctor.emit('mounted', app, sharedClass, remotes);
|
||||||
|
|
|
@ -103,11 +103,14 @@ Model.setup = function () {
|
||||||
var options = this.settings;
|
var options = this.settings;
|
||||||
var typeName = this.modelName;
|
var typeName = this.modelName;
|
||||||
|
|
||||||
|
var remotingOptions = {};
|
||||||
|
extend(remotingOptions, options.remoting || {});
|
||||||
|
|
||||||
// create a sharedClass
|
// create a sharedClass
|
||||||
var sharedClass = ModelCtor.sharedClass = new SharedClass(
|
var sharedClass = ModelCtor.sharedClass = new SharedClass(
|
||||||
ModelCtor.modelName,
|
ModelCtor.modelName,
|
||||||
ModelCtor,
|
ModelCtor,
|
||||||
options.remoting
|
remotingOptions
|
||||||
);
|
);
|
||||||
|
|
||||||
// setup a remoting type converter for this model
|
// setup a remoting type converter for this model
|
||||||
|
|
|
@ -351,4 +351,26 @@ describe('app', function() {
|
||||||
var app = loopback();
|
var app = loopback();
|
||||||
expect(app.loopback).to.equal(loopback);
|
expect(app.loopback).to.equal(loopback);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('normalizeHttpPath option', function() {
|
||||||
|
var app, db;
|
||||||
|
beforeEach(function() {
|
||||||
|
app = loopback();
|
||||||
|
db = loopback.createDataSource({ connector: loopback.Memory });
|
||||||
|
});
|
||||||
|
|
||||||
|
it.onServer('normalizes the http path', function(done) {
|
||||||
|
var UserAccount = PersistedModel.extend(
|
||||||
|
'UserAccount',
|
||||||
|
{ name: String },
|
||||||
|
{
|
||||||
|
remoting: { normalizeHttpPath: true }
|
||||||
|
});
|
||||||
|
app.model(UserAccount);
|
||||||
|
UserAccount.attachTo(db);
|
||||||
|
|
||||||
|
app.use(loopback.rest());
|
||||||
|
request(app).get('/user-accounts').expect(200, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue