2016-05-06 19:02:21 +00:00
|
|
|
// Copyright IBM Corp. 2016. All Rights Reserved.
|
|
|
|
// Node module: loopback-connector-remote
|
|
|
|
// This file is licensed under the MIT License.
|
|
|
|
// License text available at https://opensource.org/licenses/MIT
|
|
|
|
|
2016-09-01 08:12:12 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-01-07 06:45:29 +00:00
|
|
|
var loopback = require('loopback');
|
|
|
|
var remoteConnector = require('..');
|
|
|
|
|
|
|
|
exports.createMemoryDataSource = createMemoryDataSource;
|
|
|
|
exports.createModel = createModel;
|
|
|
|
exports.createRemoteDataSource = createRemoteDataSource;
|
|
|
|
exports.createRestAppAndListen = createRestAppAndListen;
|
|
|
|
exports.getUserProperties = getUserProperties;
|
|
|
|
|
2016-02-05 12:29:43 +00:00
|
|
|
function createRestAppAndListen() {
|
2016-01-07 06:45:29 +00:00
|
|
|
var app = loopback();
|
|
|
|
|
|
|
|
app.set('host', '127.0.0.1');
|
2016-02-05 12:29:43 +00:00
|
|
|
app.set('port', 0);
|
2016-01-07 06:45:29 +00:00
|
|
|
|
|
|
|
app.use(loopback.rest());
|
|
|
|
app.locals.handler = app.listen();
|
|
|
|
|
|
|
|
return app;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createMemoryDataSource() {
|
|
|
|
return loopback.createDataSource({connector: 'memory'});
|
|
|
|
}
|
|
|
|
|
|
|
|
function createRemoteDataSource(remoteApp) {
|
|
|
|
return loopback.createDataSource({
|
|
|
|
url: 'http://' + remoteApp.get('host') + ':' + remoteApp.get('port'),
|
|
|
|
connector: remoteConnector
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to create models based on a set of options. May associate or link to an
|
|
|
|
* app.
|
|
|
|
*/
|
|
|
|
function createModel(options) {
|
|
|
|
var Model = loopback.PersistedModel.extend(options.parent, options.properties,
|
|
|
|
options.options);
|
|
|
|
if (options.app) options.app.model(Model);
|
|
|
|
if (options.datasource) Model.attachTo(options.datasource);
|
|
|
|
return Model;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getUserProperties() {
|
|
|
|
return {
|
|
|
|
'first': String,
|
|
|
|
'last': String,
|
|
|
|
'age': Number,
|
|
|
|
'password': String,
|
|
|
|
'gender': String,
|
|
|
|
'domain': String,
|
|
|
|
'email': String
|
|
|
|
};
|
|
|
|
}
|