Tag: sails.js

SailsJS – Nodejs的https请求。 发送后无法设置标题

我是Sails.js的新手,我试图做一个filter来授权使用从更高的服务器,一个守门员,从GitHub API进行OAuth2身份validation负责的持证人令牌。 服务stream运作良好。 我已经知道了Passport.js,但是我正试图自己实现这个。 我带来了一个如下的policy : module.exports = function (req, res, next) { var httpsExec = require('https'); if (req.headers.authorization) { var parts = req.headers.authorization.split(' '); if (parts.length == 2) { var tokenType = parts[0] , credentials = parts[1]; if (/^Bearer$/i.test(tokenType) || /^bearer$/i.test(tokenType)) { httpsExec.request({ host: 'api.github.com', post: 443, path: '/user', method: 'GET', headers: {'Authorization': 'token […]

在Openshift上部署sails.js

我正在尝试将一个sails.js应用程序(sails.js版本0.11)部署到Openshift。 我知道以前的问题和答案在这里例如; https://gist.github.com/mdunisch/4a56bdf972c2f708ccc6我遵循了该post的步骤。 我也通过git://github.com/ryanj/nodejs-custom-version-openshift.git创build我的应用程序,所以我有sailsjs所需的最低npm版本。 仍然应用程序不启动。 有没有人试图在openshift上部署sails v0.11应用程序? 谢谢 我在下面的日志中看到 DEBUG: Running node-supervisor with DEBUG: program 'server.js' DEBUG: –watch '/var/lib/openshift/55a4256b5973cadc8400000d/app-root/data/.nodewatch' DEBUG: –ignore 'undefined' DEBUG: –extensions 'node|js|coffee' DEBUG: –exec 'node' DEBUG: Starting child process with 'node server.js' DEBUG: Watching directory '/var/lib/openshift/55a4256b5973cadc8400000d/app-root/data/.nodewatch' for changes. Listening on 127.2.103.1, port 8080 DEBUG: Sending SIGTERM to child…

如何实现模型本身的嵌套 – Mongodb&Sails

到目前为止,我已经明白了这三种模式: 用户模型 module.exports = { schema: true, attributes: { // Relations maps: { collection: 'Map' }, } }; 地图模型 module.exports = { schema: true, attributes: { // Relations owner: { model: 'User' }, spots: { collection: 'Spot', via: 'map' }, } }; 现货型号 module.exports = { schema: true, attributes: { // Relations map: { model: […]

当Content-Type为text / csv时,Sails.js正文内容

我是否需要做任何特殊的处理POST请求与文本ish Content-Type ? 我需要处理text/csv但是当我到我的控制器中的方法,它看起来像Sails.js试图parsing正文为JSON: postStuff: function(req, res) { sails.log.info("postStuff") sails.log.info(req.body) sails.log.info(req.headers['content-type']); …etc… 给我: info: postStuff info: {} info: text/csv 我发现bodyParser中间件的文档有些模糊。 FWIW,我也尝试在请求中将Content-Type设置为text/plain ,但是无济于事。 我也尝试明确添加一个文本bodyParser作为中间件,这似乎没有任何效果: http.js module.exports.http = { bodyParserText: require('body-parser').text(), middleware: { order: [ 'startRequestTimer', 'cookieParser', 'session', 'myRequestLogger', 'bodyParser', 'bodyParserText', 'handleBodyParserError', 'compress', 'methodOverride', 'poweredBy', '$custom', 'router', 'www', 'favicon', '404', '500' ], …etc…

如何正确设置Sails应用程序的原生Redis连接?

我想为我的帆应用程序使用redis连接,但我不想使用帆,因为我不会绑定到任何模型。 所以我确定了我应该遵循的步骤。 使用任何节点适配器连接Redis。 这可能应该在bootstrap sails过程中完成。 在全球范围内公开Redis并/或将其绑定到服务。 然后我很困惑,因为我不知道如何全局公开任何对象,并在需要的情况下,使用redis准备函数并绑定到任何自定义服务。 我怎样才能做到这一点?

水线:尝试访问未定义的收集string

我用Sails.js使用Waterline。 我想要一个拥有Involved的用户 。 一个事件可以有多个参与 。 一个参与有一个地位。 我的用户类: module.exports = { attributes: { involvements: { collection: 'Involvement', via : 'user' } } }; 我的活动class级: module.exports = { attributes: { creator: { model: 'User' }, involvements: { collection: 'Involvement', via: 'event' } } }; 我的参与课: module.exports = { attributes: { status: { type: 'string', required: true }, […]

SailsJS使用一个Controller操作调用两个Service方法

我对于学习全堆栈开发,特别是后端的东西是相当陌生的,并且正试图弄清这个asynchronous的Nodejs的东西。 在提交忘记的密码表单时,我需要完成一些后端操作。 基本上控制器的行为看起来像这样( 我知道肯定是做错了 ): forgot: function (req, res) { var token = "febfoebfoui38383303cnc"; var userEmail = req.body.email; var host = req.headers.host; AuthService.saveResetPasswordValues(token, userEmail, function (err, savedRecord) { if (err) { return res.send(404, '\n\nerror occurred\n\n'); } return res.json(savedRecord); }); AuthService.sendForgotPasswordEmail(token, userEmail, host, function (err, message) { if (err) { return res.send(404, '\n\nerror occurred\n\n'); } return […]

在sailsjs或expressjs应用的路由上select性地应用CSRF令牌约束

是否可以有select地将CSRF标记检查应用于某些请求/路由? 如果我想申请在我的申请中使用的6个职位申请中的4个,是否有可能? CSRF令牌是否与GET请求有关联? 作为sailsjs的参考文档说:“当启用CSRF保护时,对Sails服务器的所有非GET请求都必须附带一个特殊标记,由查询string或HTTP主体中的标头或参数标识。 普通的基于expressjs的应用程序是否一样?

在定时器+一个条件上删除logging

我的程序是一个在线游戏。 我创build一个包含玩家的游戏对象。 如果没有其他玩家(不是创build游戏的玩家)join游戏,我想在3小时后删除游戏logging。 我可以指望玩家,我知道有关mongodb的TTL,但是我怎样才能设置一个只会触发的TTL,就是没有多个玩家?

如何在一个操作中保存SailsJS中的多个logging?

我想知道最好的做法是保存多个logging的操作,使更改,特别是添加和删除多个logging。 最终目标是让一个function可以访问操作中所有已更改的数据。 目前我正在嵌套保存,以便最内层的保存可以访问所有更新logging中的数据。 这里是我如何保存的一个例子: record1.save(function (error, firstRecord) { record2.save(function (erro, secondRecord) { record3.save(function (err, thirdRecord) { res.send({recordOne: firstRecord, recordTwo: secondRecord, recordThree: thirdRecord}); }); }); }); 通过这种保存结构,recordOne,recordTwo和recordThree在服务器上显示期望值。 但是,检查localhost / 1337 / modelName显示模型没有正确更新,并有不正确的数据。