Tag: sails.js

sailsjs beforeCreate没有被触发

我有一个非常基本的模型的空船0.9.8应用程序: module.exports = { attributes: { nickname: 'string', encryptedPassword: 'string', beforeCreate: function(values, next){ values.encryptedPassword = "123"; next(); } } }; 当我从控制台创build一个新的用户时,beforeCreate方法不被调用,因此没有创buildencryptedPassword。 我敢肯定,我在这里错过了一些东西,但无法find什么。 任何想法 ?

如何使用群集风格(使用更多的核心)?

我正在尝试使用cluster库启动sails.js应用程序,以便它可以产生更多的进程来使用我的机器的所有内核,但不知何故,这里使用express的方法会失败。 var cluster = require('cluster'), numCPUs = require('os').cpus().length; // create the server if (cluster.isMaster) { for (var i = 0; i < numCPUs; i++) { cluster.fork(); } cluster.on('exit', function(worker, code, signal) { console.log('worker %d died (%s). restarting…', worker.process.pid, signal || code); cluster.fork(); }); } else { // Start sails and pass it command line arguments […]

Sail.js – 如何创build一个干净的日志文件?

我目前正在使用Sails v0.10.0-rc7并试图将控制台日志转发到一个文件。 一些较老的线程描述了通过config/log.js添加到config/log.js来实现这一点的方法: module.exports = { log: { level: 'info', filePath: 'someFile.log' } }; 但是这似乎并没有工作了。 Sails使用以前封装winston的子项目队长 – 日志 。 根据README.md,我将config/log.js改为: var winston = require('winston'); module.exports = { 'log': { 'custom': new (winston.Logger)({ 'transports': [ new (winston.transports.Console)({ 'level': 'info', 'colorize': true, 'timestamp': false, 'json': false }), new winston.transports.File({ 'level': 'debug', 'colorize': false, 'timestamp': true, 'json': true, […]

Sails.js:如何实际运行testing

我对帆,节点和js是全新的,所以我可能会漏掉一些明显的东西。 我正在使用风帆0.10.5和节点0.10.33。 在sails.js文档中有一个关于testinghttp://sailsjs.org/#/documentation/concepts/Testing的页面,但是它并没有告诉我如何真正运行它们。 我已经根据该文档设置了目录,添加了一个名为test / unit / controllers / RoomController.test.js的testing,现在我希望它运行。 没有“帆testing”命令或类似的东西。 我也没有find有关如何添加任务的任何迹象,所以testing总是在“帆升”之前运行。

拒绝连接! selenium服务器启动了

我inheritance了一个没有文档的项目。 这是一个sails.js应用程序。 有一小组unit testing和一个端到端的testing。 当我尝试使用grunt运行端到端testing时。 我得到: $ grunt e2e Running "nightwatch" task started – PID: 5440 >> Executing "default" tests (standalone) [Index] Test Suite ================== Running: Should clean the collection removing 0 places >> Connection refused! Is selenium server started? 我不知道我可能会错过什么。 这让我坚持了一个多星期。 该项目有一个selenium服务器独立-2.40.0.jar在咕night声夜表。 所以我把这个PID是selenium服务器启动的。 如果我先启动jar(外面的咕噜声)我得到 $ grunt e2e org.openqa.grid.selenium.GridLauncher main INFO: Launching a standalone server […]

模型动作的Sails.jsauthentication

我正在制作一个具有不同访问级别的API,“客户端”只能读取。 但“pipe理员”必须有写权限。 在Sails.js中,每次检查不同的angular色作为策略,并在req.session中设置权限。 我只需要给“客户端”无权创build,更新和删除操作,因此我创build了一个控制器,具有这些CRUD操作,并检查用户是否有正确的angular色。 所有限制访问的操作都通过routes.jsredirect到此控制器。 现在我的问题是,当我删除一个条目,如:Category.destroy(req.param('id')); 给我没有定义,并没有完成的方法。 不像文中提到的,我通过创build这个来解决这个问题: var deleted = Category.destroy(req.param('id'), function(err, status) { if (status == 1){ res.json({message: 'Category is deleted'}); } else { res.json({message: 'Oops, something went wrong'}); } }); 但是必须有另一种方式来对这些基本操作进行身份validation。 因为现在我必须写下所有的动作。 我写的删除函数的代码有问题吗? 是否可以应用策略并redirect到默认的模型操作,就好像根本没有authentication一样?

不能在sailsjs中unit testing我的模型

对于我的帆应用程序,我使用下面的代码来unit testing用户模型,但得到了错误信息: 'TypeError:对象#没有方法'创build'' var User = require('../../api/models/User'); var Sails = require('sails'); console.log(User); describe("User Model:", function() { // create a variable to hold the instantiated sails server var app; // Global before hook before(function(done) { // Lift Sails and start the server Sails.lift({ log: { level: 'error' }, }, function(err, sails) { app = sails; done(err, […]

我如何处理帆中独特的领域?

我已经在我的模型中定义了一个独特的字段,但是当我试图testing它似乎不被Error (E_UNKNOWN) :: Encountered an unexpected error: MongoError: E11000 duplicate key error index:检查,因为我得到一个Error (E_UNKNOWN) :: Encountered an unexpected error: MongoError: E11000 duplicate key error index:而不是validation错误。 处理风帆独特领域的最佳方法是什么? // model/User.js module.exports{ attributes: { email: {required: true, unique: true, type: 'email' }, …. } // in my controller User.create({email: 'hello@gmail.com'}).then(…).fail(….) User.create({email: 'hello@gmail.com'}).then(…).fail(// throws the mongo error ) // […]

我应该学习Express.js还是Sails.js?

我正在学习node.js。 我已经经历了一些nodeJS框架,就像expressJS和sailsJS一样,但不能决定我应该select哪个框架?

sails.js + waterline一对多模型关联,删除Many时应该发生什么?

我和老师(一)和孩子(老师)之间有一对多的关系。 如果我做: Teacher.destroy(teacherId).exec(function(err){}); 孩子们不会自动移除。 这是一个错误,或者我应该手动删除它们? 如果这不是一个错误,不删除孩子的解释是什么?