sails.js

sailsjs send a file on the fly with res.attachment()

你说的曾经没有我的故事 提交于 2019-12-24 11:26:50
问题 I would like to send a file to a client using something like res.attachment() in sailsjs. I do not want to store the file on the server at all, I simply want to generate it constantly and send it to the client. For example, my controller looks like this file: function(req, res, next) { var name = req.param('name'); var data = 'Welcome Mr/Mrs ' + name res.attachment(data, 'fileName.txt') res.send() }, Couple of problems 1) res.attachment does not seem to accept a file name as a parameter 2)

How to use OrientDB in a SailsJS App

走远了吗. 提交于 2019-12-24 11:20:05
问题 I am new to NodeJS and SailsJS, was working with Rails or PHP before. I want to use SailsJS together with OrientDB. What would be the best approach? I found two options so far, but the amount of information isn't that great (yet). Go with Waterline and this sails adapter for orientdb Go one level deeper and use the binary adapter from nodejs Any help, tips, hints would be greatly appreciated. I am a bit lost but very excited to understand more about these great tools. Thanks! 回答1: You

Use Cloud SDK in unit tests

给你一囗甜甜゛ 提交于 2019-12-24 10:55:13
问题 I followed the guide here - https://sailsjs.com/documentation/concepts/testing So my lifecycle.test.js looks like this: var sails = require('sails'); // Before running any tests... before(function(done) { // Increase the Mocha timeout so that Sails has enough time to lift, even if you have a bunch of assets. this.timeout(5000); sails.lift({ // Your sails app's configuration files will be loaded automatically, // but you can also specify any other special overrides here for testing purposes. /

$scope with dot (.) not initializing values to input fields in angular

会有一股神秘感。 提交于 2019-12-24 10:45:59
问题 In my form: <div ng-controller="myCtrl" ng-init="init('<%=JSON.stringify(data)%>')"> <input type="text" ng-model="Reg.email" /> </div> In my angular controller myApp.controller("myCtrl", ['$scope', '$http', '$parse', function($scope, $http, $parse) { $scope.init = function(myJsonData){ if(myJsonData!=null) { var myData = angular.fromJson(myJsonData); $scope.Reg.email = "test@example.com"; } }; }]); The above code will not initialize the values to the input field. But if i change model name by

Can\'t set headers after they are sent

强颜欢笑 提交于 2019-12-24 09:07:09
问题 I am trying to replicate the Sails application from this video. Here is my UserController : module.exports = { 'new': function(req, res) { res.view() }, 'create': function(req, res, next) { User.create(req.params.all(), function userCreated(err, user) { if(err) { console.log(err); req.session.flash = { err: err } return res.redirect('/user/new'); } //res.redirect('/user/show/'+user.id); res.json(user); }); }, 'show': function(req, res, next) { User.findOne(req.param('id'), function foundUser

Can\'t set headers after they are sent

跟風遠走 提交于 2019-12-24 09:05:26
问题 I am trying to replicate the Sails application from this video. Here is my UserController : module.exports = { 'new': function(req, res) { res.view() }, 'create': function(req, res, next) { User.create(req.params.all(), function userCreated(err, user) { if(err) { console.log(err); req.session.flash = { err: err } return res.redirect('/user/new'); } //res.redirect('/user/show/'+user.id); res.json(user); }); }, 'show': function(req, res, next) { User.findOne(req.param('id'), function foundUser

Sails 1.0 Models without primary key

ⅰ亾dé卋堺 提交于 2019-12-24 07:41:48
问题 I try to use new version 1.0 and refactoring my project. I have one problem and i don't now how i can solve her. Some tables on my BD don't have primary keys and when i migrate to sails 1.0, i have this error In model friends : The primary key is set to id , but no such attribute was found on the model. You must define an id attribute in api/Friends.js or in config/models.js . See http://sailsjs.com/upgrading#?changes-to-model-configuration for info Can i use my model without primary keys?

how to keep track of bounced emails or undelivered emails in sails.js

江枫思渺然 提交于 2019-12-24 06:45:47
问题 I am using nodemailer to send mails. My requirement is to keep track of bounced emails or undelivered emails. How to do that ? Please help 回答1: You cannot do this easily in the current configuration. The mail functions do not return immediately, if a mail was delivered or the recipient is unavailable. The mail is just accepted by the SMTP server and then your script goes on. The SMTP server (in the background and asynchronously) tries to send the mail (likely multiple times) and only if it

Sails js, how do we write inner join using populate

不羁岁月 提交于 2019-12-24 06:36:43
问题 Sails's populate works as Left join. I want to do as inner join, Anybody help me how we can write inner join using populate without writing raw query. I am using MYSQL adapter. 回答1: if you have for example two models user , contacts relation one-to-many you try to write something like :- first models will like this :- user.js module.exports = { schema: true, tableName: 'userdata', attributes: { anyField: { type: 'integer', required: false, size: 56, }, contacts: { collection: 'Contact', via:

SailsSocket Keep Trying to Reconnect

十年热恋 提交于 2019-12-24 06:32:23
问题 After struggling with socket.io connection authentication (here and here) and thanks to @sgress454, I realized how to get this to work and I am sending the authentication/authorization token as part of the query in the connection (see below). Upon authentication failure (invalid/expired token or in-active user), I return the callback with false parameter to indicate the connection is rejected. On the client side though, I am not sure how I should handled it and it seems the socket is trying