sails.js

socket.io issue using sails.js

走远了吗. 提交于 2019-12-13 02:22:06
问题 I am trying to use socket.io with sails js. I understood that it was pretty straighforward and that sails provided an available socket.io structure out of the box. Howeve When I try to connect to my sails server from a distant client using io.connect(http://localhost:1337) It makes my server crash with the message: /node_modules/express/node_modules/connect/lib/utils.js:216 return 0 == str.indexOf('s:') ^ TypeError: Cannot call method 'indexOf' of undefined I am probably missing something but

Should one-to-one associations populate both sides?

泄露秘密 提交于 2019-12-13 01:37:11
问题 I have two models (user & agent). I then create a user and an agent. I am expecting to see the association when using the blueprint routes for BOTH /user and /agent. I am only seeing the user model is associated with an agent via the /agent blueprint. The /user blueprint does not have any reference/association to an Agent. The issue presents itself when I am trying to access the Agent via A userId with the following command: User.findOne(req.body.userId).populate('agent').exec(function(err,

Helper for check all params node.js - sails - express

痴心易碎 提交于 2019-12-13 01:08:02
问题 I want to check my params in my controllers. For the moment, I'm doing like that: create: function (req, res) { if(req.params.label && req.params.password){ // do stuff } } But I want to do this more quickly. I'm wondering if there is no tools which already exist. I want to do things like that: create: function (req, res) { checkParams({label: {empty: false}, password: {empty: false}}, function(err){ // Do stuff }); } Do you know something which could help me? Thank you. 回答1: Okay, I'll

Sails.Js - How I can watch file/directory

依然范特西╮ 提交于 2019-12-13 00:53:35
问题 My question is about i store files (audio) in a directory with a reference in db ( mysql) and i wanna set a lifetime to this file to prevent server overflow. I search in google and sails doc but not see anything reference, Anyone know how to i can watch the file to remove after do the time? 回答1: The best way its make a php file to call an localhost url [you can make a route locally by policies] and call that file with crontab every x/time just do: task.php <?php $url = 'http://localhost:1337

Running sails throwing invalid character error

两盒软妹~` 提交于 2019-12-12 22:12:51
问题 I have installed sails successfully using npm install sails -g I am running Windows 7. When I tried to run the 'sails' command, got error saying "command not found". Then I included the corresponding bin folder in PATH env variable. Then getting javascript error while trying to run 'sails' command. ERROR:: Line: 1 Char: 1 Error: Invalid character Code: 800A03F6 Source: Microsoft JScript compilation error 回答1: This happens because you need to run sails.js with node.bat. To do so, first make

Sails js application driving CPU usage to 100%

霸气de小男生 提交于 2019-12-12 22:08:00
问题 I'm building a an application using sails and every time I leave the server running for more than a few minutes my CPU jumps to a solid 100% usage. I'm including a big amount of less files in my assets and I believe my issue lies here. Are there any other reasons this may happen? 回答1: It could be the grunt-watch, when you have a lot of files it squeezes your cpu. Try disabling that and check if your cpu gets to a normal usage (6-30% depending on your cpu and overall usage). To do that go to

How to use sails-auth in sails project?

北慕城南 提交于 2019-12-12 20:30:22
问题 How can I use sails-auth hook in my sails project? I installed sails-auth using npm install sails-auth --save. and when running project terminal logs says sails-auth controllers, services, models are loaded using marlinspike. But I don't have any idea about further steps. Please help me.. 回答1: sails-auth is a Passport-based User Authentication system for Sails.js applications. When u run npm install sails-auth --save , it will install sails-auth as a Sails Hook. The Hook uses marlinspike to

Can I specify a lifecycle callback that fires for all waterline models in sails.js

柔情痞子 提交于 2019-12-12 19:41:15
问题 I'm trying to add some auditing capability to my sails.js app. The afterUpdate lifecycle callback will give me the proper place to do what I need, but I'm hoping to avoid modifying every model to reference my new code. Is there a way to specify an afterUpdate callback that will fire on all models? 回答1: Put your required overrides into config/models.js module.exports.models = { attributes: {}, afterUpdate: function (valuesToUpdate, cb) { // add your logic here... console.log('yep, updated');

Get current user from inside the model in Sails

不羁的心 提交于 2019-12-12 17:31:25
问题 I'm using toJSON() method of my model in Sails in order to control the visibility of some of it's properties, when model is exposed via application's API. In order to decide which properties to display and which to omit I need to know the permissions of the current user. So, how do I get the current user from inside the model? Or is there a better way (pattern) to solve this problem? Here's some sample code I want to achieve: toJSON: function () { var result = {}; result.firstName = this

sails.js: Lifecycle callbacks for Models: Do they support beforeFind and afterFind?

╄→гoц情女王★ 提交于 2019-12-12 15:56:48
问题 In sails.js, Models support lifecycle callbacks for validate, create, update and destroy. Is there support for callbacks for find() or query as well? Like beforeFind() and afterFind()? The idea is same. I would want to validate / modify parameters before the query is run or after the query is run. Any thoughts? 回答1: As of writing this it does NOT support these requests, however their is a pull request https://github.com/balderdashy/waterline/pull/525 You can use policies to do this in the