Allows options to be passed to strong-remoting

This commit is contained in:
Raymond Feng 2014-02-19 15:14:31 -08:00
parent 088c2e2296
commit 37646fa008
6 changed files with 85 additions and 14 deletions

View File

@ -56,7 +56,8 @@ app.remotes = function () {
if(this._remotes) { if(this._remotes) {
return this._remotes; return this._remotes;
} else { } else {
return (this._remotes = RemoteObjects.create()); var options = this.get('remoting') || {};
return (this._remotes = RemoteObjects.create(options));
} }
} }
@ -213,14 +214,6 @@ app.remoteObjects = function () {
return result; return result;
} }
/**
* Get the apps set of remote objects.
*/
app.remotes = function () {
return this._remotes || (this._remotes = RemoteObjects.create());
}
/** /**
* Enable swagger REST API documentation. * Enable swagger REST API documentation.
* *

View File

@ -3,7 +3,6 @@
*/ */
var loopback = require('../loopback'); var loopback = require('../loopback');
var RemoteObjects = require('strong-remoting');
/** /**
* Export the middleware. * Export the middleware.
@ -23,7 +22,7 @@ function rest() {
if(req.url === '/routes') { if(req.url === '/routes') {
res.send(handler.adapter.allRoutes()); res.send(handler.adapter.allRoutes());
} else if(req.url === '/models') { } else if(req.url === '/models') {
return res.send(remotes.toJSON()); return res.send(app.remotes().toJSON());
} else { } else {
handler(req, res, next); handler(req, res, next);
} }

View File

@ -3,7 +3,6 @@
*/ */
var loopback = require('../loopback'); var loopback = require('../loopback');
var RemoteObjects = require('strong-remoting');
var assert = require('assert'); var assert = require('assert');
/*! /*!

View File

@ -428,7 +428,8 @@ describe('app', function() {
assert.equal(typeof res.body, 'object'); assert.equal(typeof res.body, 'object');
assert(res.body.started); assert(res.body.started);
assert(res.body.uptime); // The number can be 0
assert(res.body.uptime !== undefined);
var elapsed = Date.now() - Number(new Date(res.body.started)); var elapsed = Date.now() - Number(new Date(res.body.started));

View File

@ -1,5 +1,14 @@
{ {
"port": 3000, "port": 3000,
"host": "0.0.0.0", "host": "0.0.0.0",
"cookieSecret": "2d13a01d-44fb-455c-80cb-db9cb3cd3cd0" "cookieSecret": "2d13a01d-44fb-455c-80cb-db9cb3cd3cd0",
"remoting": {
"json": {
"limit": "1kb",
"strict": false
},
"urlencoded": {
"limit": "8kb"
}
}
} }

View File

@ -0,0 +1,70 @@
var loopback = require('../');
var lt = require('loopback-testing');
var path = require('path');
var SIMPLE_APP = path.join(__dirname, 'fixtures', 'simple-integration-app');
var app = require(path.join(SIMPLE_APP, 'app.js'));
var assert = require('assert');
describe('remoting - integration', function () {
lt.beforeEach.withApp(app);
lt.beforeEach.givenModel('store');
afterEach(function (done) {
this.app.models.store.destroyAll(done);
});
describe('app.remotes.options', function () {
it("should load remoting options", function () {
var remotes = app.remotes();
assert.deepEqual(remotes.options, {"json": {"limit": "1kb", "strict": false},
"urlencoded": {"limit": "8kb"}});
});
it("rest handler", function () {
var handler = app.handler('rest');
assert(handler);
});
it('should accept request that has entity below 1kb', function (done) {
// Build an object that is smaller than 1kb
var name = "";
for (var i = 0; i < 256; i++) {
name += "11";
}
this.http = this.post('/api/stores');
this.http.send({
"name": name
});
this.http.end(function (err) {
if (err) return done(err);
this.req = this.http.req;
this.res = this.http.res;
assert.equal(this.res.statusCode, 200);
done();
}.bind(this));
});
it('should reject request that has entity beyond 1kb', function (done) {
// Build an object that is larger than 1kb
var name = "";
for (var i = 0; i < 2048; i++) {
name += "11111111111";
}
this.http = this.post('/api/stores');
this.http.send({
"name": name
});
this.http.end(function (err) {
if (err) return done(err);
this.req = this.http.req;
this.res = this.http.res;
// Request is rejected with 413
assert.equal(this.res.statusCode, 413);
done();
}.bind(this));
});
});
})
;