Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,14 @@ app.remoteObjects = function () {
* @triggers `mounted` events on shared class constructors (models)
*/

app.handler = function (type) {
app.handler = function (type, options) {
var handlers = this._handlers || (this._handlers = {});
if(handlers[type]) {
return handlers[type];
}

var remotes = this.remotes();
var handler = this._handlers[type] = remotes.handler(type);
var handler = this._handlers[type] = remotes.handler(type, options);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nice to have feature: allow developers to turn on/off the flag normalizeHttpPath via server/config.json.

options = extend(this.get('remoting') || {}, options);
var remotes = this.remotes();
var handler = this._handlers[type] = remotes.handler(type, options);

Usage in config.json:

{
  "port": 3000,
  "restApiRoot": "/api",
  "remoting": {
    "normalizeHttpPath": true
  }
}

@ritch @raymondfeng thoughts?
@fabien it's ok to leave this feature out of scope of this PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice to have feature: allow developers to turn on/off the flag normalizeHttpPath via server/config.json.

good idea 👍

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move the implementation outside of this PR - see #608.


remotes.classes().forEach(function(sharedClass) {
sharedClass.ctor.emit('mounted', app, sharedClass, remotes);
Expand Down
7 changes: 5 additions & 2 deletions lib/models/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,15 @@ Model.setup = function () {
var ModelCtor = this;
var options = this.settings;
var typeName = this.modelName;


var remotingOptions = {};
extend(remotingOptions, options.remoting || {});

// create a sharedClass
var sharedClass = ModelCtor.sharedClass = new SharedClass(
ModelCtor.modelName,
ModelCtor,
options.remoting
remotingOptions
);

// setup a remoting type converter for this model
Expand Down
2 changes: 1 addition & 1 deletion test/access-token.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('AccessToken', function () {
});

describe('app.enableAuth()', function() {
this.timeout(0);
this.timeout(false);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I believe this line was removed from the current master.


beforeEach(createTestingToken);

Expand Down
20 changes: 20 additions & 0 deletions test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,24 @@ describe('app', function() {
var app = 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);
});
});

});