Hello kind folks from the lovely loopback community,
Here's my situation, I setup a small repository to test connection between two loopback apps using loopback-connector-rest. I created both apps with slc lb project, so I am sure you are familiar with their structure.
I have two apps, a master app with a User model using a memory datasource, and a slave app with a User model with a loopback-connector-rest datasource and a baseUrl that points towards master app's url. You can check out the repository on github:
https://github.com/JulianMayorga/rest-connector-example
The problem is that with this setup I cannot do a POST to [slave_url]/api/users, even though I can do that with the master's url. I defined a test that proves I cannot do this:
'use strict';
var request = require('supertest');
var should = require('should');
var master = require('../master/app.js');
var slave = require('../slave/app.js');
describe('Master server', function () {
var password = '123456';
it('should return new user email and id', function (done) {
request(master)
.post('/api/users')
.send({
email: email,
password: password
})
.expect(200)
.end(function (err, res) {
res.body.email.should.equal(email);
res.body.id.should.be.an.instanceOf(Number);
done();
});
});
});
describe('Slave server', function () {
var password = '123456';
it('should return new user email and id', function (done) {
request(slave)
.post('/api/users')
.send({
email: email,
password: password
})
.expect(200)
.end(function (err, res) {
res.body.email.should.equal(email);
res.body.id.should.be.an.instanceOf(Number);
done();
});
});
});
And this is the output I get when running mocha:
POST /api/users 200 703ms - 45b
․․
1 passing (3s)
1 failing
1) Slave server should return new user email and id:
Error: timeout of 2000ms exceeded
In order to figure out what's happening here I tried to debug the app by running DEBUG=loopback:connector:rest node app.js in slave app, which outputs the following debug message:
POST /api/users 200 2015ms
So then I checked out the logs in master server, and it is effectively receiving a GET request:
GET /api/users?where[email]=anotheremail%40example.com 401 6ms - 1.06kb
I don't know why, but rest connector fires a GET request instead of a POST when I try to create a user. Does anyone know why this might happen?
I just want to have a central app that stores users and accessTokens, and secondary apps that have their own models but use the central app for users and tokens.
Thanks so much in advance,
Julián.