sails.js

Why is `req.user` undefined for socket requests in Sails.js, Angular.js and Passport.js?

情到浓时终转凉″ 提交于 2019-12-01 08:58:45
I am trying to get the questions for the current user with a request like this: http://localhost:1337/question/forme As part of the GET request, I am able to access req.user.username and serve the JSONresponse when accessing it from the browser. When I try to make the same Socket.get() request from my Angular client.js file, it doesn't work. I also tried to access it using browser console and it fails for socket.get() requests. I spent a large time figuring out all the moving parts to get passport working with sails on my blog I'll repost the relevant parts below, with an additional policy

How to get added record (not just the id) through publishAdd()-notification?

大兔子大兔子 提交于 2019-12-01 08:35:41
问题 Each Sails.js model has the method publishAdd(). This notifies every listener, when a new record was added to a associated model. This notification does not contain the newly created record. So I have to start another request from the client side to get the new record. Is there a possibility, that Sails.js sends the new record with the notification, so I can reduce my request count? Solution I realized the accepted answer like that: https://gist.github.com/openscript/7016c5fd8c5053b5e3a3 回答1:

Using mix of AND and OR clause in sails and waterline

一笑奈何 提交于 2019-12-01 07:59:39
问题 How can I use OR and AND clause in Sailsjs and its ORM Waterline? For example I have a table of books _______________________________________ | book_name | author | free | public | _______________________________________ | Book-A | Author-1 | false | true | --------------------------------------- | Book-B | Author-1 | true | true | --------------------------------------- | Book-C | Author-1 | false | false | --------------------------------------- | Book-D | Author-2 | true | true | ---------

How do I authenticate access to assets folder in sails.js

倾然丶 夕夏残阳落幕 提交于 2019-12-01 07:54:25
问题 I am already using passport to authenticate users. I added kibana 3 to the assets folder and want users to access it only if they are authenticated. how do i do this ? 回答1: The assets folder is intended for publicly-available files, like your images and Javascripts. If you want to protect those files, you can either override the default www middleware in Sails, which activates the Express static handler to servet those files (see details on overriding default middleware in this answer), or

Sort by the association with populate

…衆ロ難τιáo~ 提交于 2019-12-01 07:34:10
I have Articles and Comments linked by a one-to-many association (an Article can have many Comments). I would like to obtain the most commented articles so I proceed like that : function mostCommentedArticles () { var deferred = Q.defer(); Article.find().populate('comments').sort('comments ASC').exec(deferred.makeNodeResolver()); return deferred.promise; } BUT, I don't obtain the expected result : it doesn't sort at all (by Comments or anything else) Is there an other way to proceed or is it an issue? Thanks, Pierre Melvin You pass it in the second parameter of .populate() like this: .populate

Sails.js bodyParser - request entity too large on version 0.10.5

瘦欲@ 提交于 2019-12-01 06:29:34
I am trying to post a lot of data to my sails API and I get this 413 error: Unable to parse HTTP body- error occurred - Error: request entity too large I have tried a lot of solutions suggested in differents discussions but it never works and seems to be for previous sails version. (it’s always about changing the bodyParser options) Does anybody know the correct syntax for sails 0.10.5? Thanks a lot! Does anybody know the correct syntax for sails 0.10.5? Thanks a lot! Take a look at this resolution (sails v.0.11.0, config/http.js): module.exports.http = { middleware: { ... }, bodyParser:

Sort by the association with populate

随声附和 提交于 2019-12-01 05:53:00
问题 I have Articles and Comments linked by a one-to-many association (an Article can have many Comments). I would like to obtain the most commented articles so I proceed like that : function mostCommentedArticles () { var deferred = Q.defer(); Article.find().populate('comments').sort('comments ASC').exec(deferred.makeNodeResolver()); return deferred.promise; } BUT, I don't obtain the expected result : it doesn't sort at all (by Comments or anything else) Is there an other way to proceed or is it

Simple page app routes to same view or controller SailsJS

我怕爱的太早我们不能终老 提交于 2019-12-01 05:50:53
How can I route multiple urls to the same controller or view to work with angular single page app?! I can do this but i think is ugly.. '/': { view: 'homepage' }, '/login': { view: 'homepage' }, '/register': { view: 'homepage' }, '/troller': { view: 'homepage' }, ............ I want somethink like ['/','/login','/register','/troller'] -> view: 'homepage' And other question, Can I use regular expressions for routing? Thx!! and sorry for my english. You can't currently use real regular expressions for routing. You can however use a wildcard route to do what you want (aim multiple routes at one

Sails.js get many to many association count

白昼怎懂夜的黑 提交于 2019-12-01 04:50:17
I have a model (user) that has an association with another model (phone). This association is many to many. The following call is built in to Sails and allows me to get all the phone records for a particular user: GET - /user/:userId/phones I would like to be able to implement pagination on that call but cannot figure out how to get the total number of results. I've tried overwriting the blueprints find.js and/or findOne.js in order to return the count but the call above doesn't seem to run through that logic. Great question. Sails implements many-to-many associations using a "join" model. It

sails.js + waterline One-To-Many model association, what should happen when deleting the Many?

放肆的年华 提交于 2019-12-01 04:28:33
I have a one to many relation between Teacher(One) and Children(Many). If I do: Teacher.destroy(teacherId).exec(function(err){}); The children are not automatically removed. Is it a bug or should I delete them manually? If that's not a bug, what is the explanation for not deleting children? Waterline currently doesn't support cascading deletes. It may be a configuration option in future versions, but it will probably never be the default. In most production-ready apps you probably should be doing soft-deletes anyway. In either case, you can get what you want by using the afterDestroy lifecycle