Merge pull request #77 from agriwebb/pass-args-connector

Add support for configuring remoting options
This commit is contained in:
Miroslav Bajtoš 2017-12-05 14:42:53 +01:00 committed by GitHub
commit 607fec76be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 2 deletions

View File

@ -29,14 +29,14 @@ module.exports = RemoteConnector;
function RemoteConnector(settings) {
assert(typeof settings ===
'object',
'cannot initiaze RemoteConnector without a settings object');
'cannot initialize RemoteConnector without a settings object');
this.client = settings.client;
this.adapter = settings.adapter || 'rest';
this.protocol = settings.protocol || 'http';
this.root = settings.root || '';
this.host = settings.host || 'localhost';
this.port = settings.port || 3000;
this.remotes = remoting.create();
this.remotes = remoting.create(settings.options);
this.name = 'remote-connector';
if (settings.url) {

View File

@ -12,6 +12,7 @@ var remoteConnector = require('..');
exports.createMemoryDataSource = createMemoryDataSource;
exports.createModel = createModel;
exports.createRemoteDataSource = createRemoteDataSource;
exports.createRemoteDataSourceWithOptions = createRemoteDataSourceWithOptions;
exports.createRestAppAndListen = createRestAppAndListen;
exports.getUserProperties = getUserProperties;
@ -44,6 +45,14 @@ function createRemoteDataSource(remoteApp) {
});
}
function createRemoteDataSourceWithOptions(remoteApp, options) {
return loopback.createDataSource({
url: 'http://anyURL.com',
connector: remoteConnector,
options: options
});
}
/**
* Used to create models based on a set of options. May associate or link to an
* app.

View File

@ -134,3 +134,15 @@ describe('Custom Path', function() {
});
});
});
describe('RemoteConnector with options', () => {
it('should have the remoting options passed to the remote object', () => {
const serverApp = helper.createRestAppAndListen();
const datasource = helper.createRemoteDataSourceWithOptions(
serverApp,
{'test': 'abc'});
assert.deepEqual(datasource.connector.remotes.options, {test: 'abc'});
});
});