sails.js

sails.js Getting a POST payload with text/plain content type

好久不见. 提交于 2019-12-06 13:52:01
I'm developing a sails.js (node.js framework based on express) aplication, which is going great but ]I can't solve this detail... I need to send POST requests cross domain from internet explorer 8 and 9. For that I'm forced to use xDomainRequest object, wich doesn't allow to set a Content type header. So, when the request gets to the server the content type is "text/plain", which doesn't fire the bodyParser express middleware, so my req.body is an empty object and I can't see the payload I'm sending from the client. For this I've tried two things with no luck: First I wanted to set a header to

Sails.js Associations many-to-many relation

丶灬走出姿态 提交于 2019-12-06 13:43:36
问题 I have a problem with many to many relationship in sails and if somebody can help me it would be great :D I have two models User and Message and the associations is defined as follows api/models/User.js module.exports = { attributes: { messages: { collection: 'message', via: 'owner', dominant: true } } }; api/models/Message.js module.exports = { attributes: { owner: { model: 'user'. via: 'messages' } } }; I checked in the DB (MySQL) the middle table is created and i successfully inserted the

sails can't find layout.jade

北城以北 提交于 2019-12-06 13:42:28
I am starting to learn Sails (0.9.7, node 0.10.16) and running through the sailscasts episodes. I am also trying to use jade as I do so. Where I am stuck now is that sails is not finding views/layout.jade. I backed out all the jade stuff and redid with ejs and sails is not finding views/layout.ejs. As a last resort, I cloned activtyoverlord (the sailscasts app) and when I sails lift activityoverlord does not find its views/layout.ejs. Any suggests as to what I might be doing wrong? I'm not a jade user, however, I think you need to put extends ../layout at the top of your index.jade file to use

picture do not show in sails.js view

坚强是说给别人听的谎言 提交于 2019-12-06 13:32:25
问题 My assets folder : assets | images | media | book | pictures i want to create new book when i upload book picture in above path, But when i try to show this image in view, the image can not be displayed and there is no error either. my code is: //BookController create: function (request, response, next) { var title = request.body.title; var subject = request.body.subject; var brief = request.body.brief; var author = request.body.author; var origin_pic_name = null; request.file('pic').upload({

Deploy sails.js to Windows Azure Website

岁酱吖の 提交于 2019-12-06 13:06:00
I'm following this guide on installing a node.js application on Azure: http://www.windowsazure.com/en-us/develop/nodejs/tutorials/create-a-website-(mac)/#header-0 Is it possible to get a sails.js app running without having to instantiate a Virtual Machine? As of right now sails requires an npm install -g on the box which would require either a virtual machine or a cloud service with a startup script. The link you are showing if for a deployment model where you don't get any access to manipulate the host since there are many instances running on it. It would be great if sails could be included

How to translate models in Sails.js?

戏子无情 提交于 2019-12-06 13:01:15
问题 I'm working on a simple app with a few models which need to have multilingual attributes. E.g., a model "Article" with a "title" string attribute should have translation for English and French. I'm aware that Sails.js ships with I18n node module, but that seems to handle hardcoded string translations only. Does anyone have any experience with this or sample code to point me to? I'm looking for a best practice here, if possible. 回答1: You can do it 2 ways: 1.) Duplicate the fields in you model

Service that returns data from an asynchronous method

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 12:45:37
I am using Sails' ORM (Waterline). I have written a geturl service that should return the url of several models/actions in my app. I am currently calling this service inside my templates. (As I am alone to develop this, don't hesitate to warn me if this design pattern is wrong) Now it occurs that Waterline's .find() method is asynchronous (as it should). I always use callbacks to do things when inserting or fetching things in database. Now I have seen everywhere that I cannot return any data from asynchronous methods. As a consequence I am puzzled because I want to create this [damned] service

How to use socketio for showing Online/Offline User in Real Time Using Sails?

£可爱£侵袭症+ 提交于 2019-12-06 12:25:52
问题 My Real Time Chat App is based on Sails and SocketIO.It shows all users along with available online users .When a User logged in,a UserConnected socket is emitted and When a User is disconnected,a UserDisconnected socket is emitted , My Server side socketio code in config/sockets.js is onConnect: function(session, socket) { if (session.passport) { if (session.passport.user && socket.id) { sails.io.sockets.emit('UserConnected', {userID : session.passport.user}); } } } //// By default: do

setheader gives error: “throw new Error('Can\\'t set headers after they are sent.');”

泄露秘密 提交于 2019-12-06 11:59:40
Getting this error while checking whether the user already voted or not. I suggest setheader thing is responsible. CODE index : function(req, res, next){ if(req.method == "POST"){ var aa = Users.findOneByEmail(req.param('email'), function(err, data, next){ if(err) res.serverError(err); console.log(data); if(data){ res.redirect('/users'); return; } }); var data = { remoteip: req.ip, challenge: req.body.recaptcha_challenge_field, response: req.body.recaptcha_response_field }; // console.log(data); var recaptcha = new Recaptcha(PUBLIC_KEY, PRIVATE_KEY, data); recaptcha.verify(function(success,

How can I select different databases for a model based on request parameters in Sails.js?

孤人 提交于 2019-12-06 11:39:35
问题 I have an application that I am considering porting to Sails.JS. One of the big issues I am having is supporting the per-request database selection that we have right now. Our app creates/uses a different database for each customer that we have and we select the database based on the request. How could I achieve that in Sails.JS? Could I write a Express middleware that would do this on a per request basis? 来源: https://stackoverflow.com/questions/26930432/how-can-i-select-different-databases