2020-02-10 18:49:27 +00:00
|
|
|
// Copyright IBM Corp. 2016,2019. All Rights Reserved.
|
2016-05-06 19:02:21 +00:00
|
|
|
// 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';
|
|
|
|
|
2019-10-03 08:54:13 +00:00
|
|
|
const extend = require('util')._extend;
|
|
|
|
const loopback = require('loopback');
|
|
|
|
const remoteConnector = require('..');
|
2016-01-07 06:45:29 +00:00
|
|
|
|
|
|
|
exports.createMemoryDataSource = createMemoryDataSource;
|
|
|
|
exports.createRemoteDataSource = createRemoteDataSource;
|
|
|
|
exports.createRestAppAndListen = createRestAppAndListen;
|
|
|
|
exports.getUserProperties = getUserProperties;
|
|
|
|
|
2016-02-05 12:29:43 +00:00
|
|
|
function createRestAppAndListen() {
|
2017-12-11 13:45:43 +00:00
|
|
|
const app = loopback({localRegistry: true});
|
2016-01-07 06:45:29 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2016-09-01 08:24:56 +00:00
|
|
|
app.set('legacyExplorer', false);
|
|
|
|
app.set('remoting', {
|
2017-12-11 13:51:48 +00:00
|
|
|
errorHandler: {debug: true, log: false},
|
2016-09-01 08:24:56 +00:00
|
|
|
context: false,
|
|
|
|
});
|
|
|
|
|
2016-01-07 06:45:29 +00:00
|
|
|
app.use(loopback.rest());
|
|
|
|
app.locals.handler = app.listen();
|
|
|
|
|
|
|
|
return app;
|
|
|
|
}
|
|
|
|
|
2017-12-11 13:45:43 +00:00
|
|
|
function createMemoryDataSource(app) {
|
|
|
|
return app.dataSource('db', {connector: 'memory'});
|
2016-01-07 06:45:29 +00:00
|
|
|
}
|
|
|
|
|
2017-12-11 13:45:43 +00:00
|
|
|
function createRemoteDataSource(app, serverApp) {
|
|
|
|
return app.dataSource('remote', {
|
|
|
|
url: 'http://' + serverApp.get('host') + ':' + serverApp.get('port'),
|
2017-12-11 13:51:48 +00:00
|
|
|
connector: remoteConnector,
|
2016-01-07 06:45:29 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getUserProperties() {
|
|
|
|
return {
|
|
|
|
'first': String,
|
|
|
|
'last': String,
|
|
|
|
'age': Number,
|
|
|
|
'password': String,
|
|
|
|
'gender': String,
|
|
|
|
'domain': String,
|
2017-12-11 13:51:48 +00:00
|
|
|
'email': String,
|
2016-01-07 06:45:29 +00:00
|
|
|
};
|
|
|
|
}
|