Socket.IO server hangs up

Issue I am new to socket.io. So my socket.io server sometimws crashes giving this below error timers.js:103 if (!process.listeners(‘uncaughtException’).length) throw e; ^ Error: socket hang up at createHangUpError (http.js:1360:15) at ServerResponse.OutgoingMessage._writeRaw (http.js:507:26) at ServerResponse.OutgoingMessage._send (http.js:476:15) at ServerResponse.OutgoingMessage.write (http.js:749:16) at XHRPolling.doWrite

Continue reading

How to set cache headers only if there isn't an error in sending the response in Node.js

Issue I am doing this essentially: app.get(‘/:id.:ext’, (req, res) => { const remote = bucket.file(`images/${req.params.id}.${req.params.ext}`) // if (isProd) // res.set(‘Cache-Control’, ‘public, max-age=604800’) remote.createReadStream({ validation: false }) .on(‘error’, error => { console.log(error) res.send(`data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7`) }) .pipe(res) .on(‘end’, () => { res.set(‘Cache-Control’, ‘public,

Continue reading

Custom validation errors gets set multiple times

Issue I created a custom validation for one of my models properties the following way: Model.validateAsync(‘minOsVersion’, validateMinimumOsVersion, {message: ‘Minimum OS Version incorrect’}); function validateMinimumOsVersion(err, done) { var requiredVersion = “some version”; var givenVersion = this.minOsVersion; if (validator.validateSemanticVersionString(givenVersion, requiredVersion) < 0)

Continue reading

Promisfy loopback models

Issue In unit testing Loopback it is necessary to use callbacks with the upsert methods. So for example … instead of writing something along the lines of this: before(function () { Student = server.models.Student Course = server.models.Course Course.upsert({id: 1, key:

Continue reading

Error "npm install -g strongloop" in ubuntu

Issue $ sudo npm install -g strongloop > heapdump@0.3.7 install /usr/lib/node_modules/strongloop/node_modules/heapdump > node-gyp rebuild gyp ERR! configure error gyp ERR! stack Error: Can’t find Python executable “/path/to/python”, you can set the PYTHON env variable. gyp ERR! stack at failNoPython (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:401:14)

Continue reading

Loopback Download file

Issue I am following the document for download the file. https://docs.strongloop.com/display/public/LB/Storage+component In that document if download the file means need to follow the url pattern. GET /containers/{container}/files/{file} Example: I have container1 (container name), and file name lb.png. So I maked

Continue reading

loopback include with two models

Issue This current code is working : app.models.AvionPiloteAutorisation.find({ “where”: { “idAvion”: avion.idAvion }, “include”: [“pilote”] }, function(err, pilotes) { … } But this : app.models.AvionPiloteAutorisation.find({ “filter”: { “where”: { “idAvion”: avion.idAvion }, “include”: { “relation”: “pilote” } } }) fail.

Continue reading

Loopback update model after save

Issue I want to update last inserted/updated document(row) in “after save” hook without create new instance of that like this: Model.observe(‘after save’, function (ctx, next) { ctx.someProperty = ‘Foo’; ctx.update(); }); How it possible? Solution I’m not sure what you

Continue reading

Is it possible to remove an operation hook?

Issue Let say I have bind an operation hook for test purpose like the following: it(‘verification link confirms mail’,function(done){ var client = app.models.client; client.observe(‘after save’, function(ctx, next) { if (!ctx.instance.verificationToken){ next(); return; } var link = ‘/api/clients/confirm?uid=’ + ctx.instance.id +

Continue reading

Operation hook for hasAndBelongsToMany

Issue How can I configure an operation hook, such as after save, when linking or unlinking an instance of the foreign model? Using loopback’s example Assembly and Part model: https://docs.strongloop.com/display/public/LB/HasAndBelongsToMany+relations I would like to execute code when adding (or removing)

Continue reading

StrongLoop: ACL for Subtable

Issue I have two tables A and B. A hasOne B, B belongsTo A. Now I have the following ACL in B: { “principalType”: “ROLE”, “principalId”: “$everyone”, “permission”: “DENY”, “accessType”: “*” } When I make a request to localhost/api/B/{id} I

Continue reading

strong-pm http auth 401

Issue I’ve installed strong-pm on an AWS linux instance: [root@box]# npm -g install strongloop strong-pm [root@box]# sl-pm-install –http-auth user:pass –force –upstart 0.6 –set-env NODE_ENV=production [root@box]# /sbin/initctl reload-configuration [root@box]# /sbin/initctl restart strong-pm strong-pm start/running, process 18171 When I attempt to check

Continue reading

loopback-storage-component how to display picture – file

Issue I am using loopback-component-storage for uploading images to server. https://docs.strongloop.com/display/public/LB/Storage+component I have also AngularJS JavaScript SDK so my lb-services.js is dynamically updated. https://docs.strongloop.com/display/public/LB/AngularJS+JavaScript+SDK Now I want to display in my webpage the photo from this loopback component storage model,

Continue reading

What's the difference between Loopback's operation hooks vs events?

Issue Loopback seems to have overlapping concepts when handling certain points of time in an model’s lifecycle: https://docs.strongloop.com/display/public/LB/Operation+hooks Applied through Model.observe vs https://docs.strongloop.com/display/public/LB/Events#Events-Modelevents Applied through Model.on Both seem to have similar ways of handling CRUD events. What’s the difference between

Continue reading

User infomation in Loopback

Issue I’m making a games backend in loopback. I have a user model defined as such. { “name”: “player”, “base”: “User”, “idInjection”: true, “options”: { “validateUpsert”: true }, “properties”: { “name”: { “type”: “string”, “required”: true } }, “validations”: [],

Continue reading