sails.js

SailsJS: beforeUpdate (Lifecycle callback), access current values

与世无争的帅哥 提交于 2019-12-24 03:26:17
问题 It's clear how to access the new values, the first argument contains them beforeUpdate: function (values, cb) {....} But how can I access the current values, that are to be replaced? 回答1: In order do access current values you will have to make the call and get the current record. models/user.js beforeCreate: function (values, cb) { User.findOne(this.update.arguments[0].id || this.update.arguments[0]).exec(err, function(originalUser){/*...*/}) } Also check out https://github.com/balderdashy

Sails.js/waterline: Executing waterline queries in toJSON function of a model?

非 Y 不嫁゛ 提交于 2019-12-24 03:25:58
问题 I have the following model, let's say it describes a book: module.exports = { attributes: { name: { type: 'String', required: true }, type: { type: 'string', required: true }, book_id: { type: 'integer' } } } Here the 'type' attribute is the genre of the book, for example HorrorBook. I have a separate model for HorrorBooks, FantasyBooks and such, since the structure of the models differs from each other so much, they have fields the other doesn't have etc, which is why I can't just use a

Listen to unix socket in sailsjs

雨燕双飞 提交于 2019-12-24 03:25:53
问题 I know it's pretty easy and possible to listen to a unix socket file in express mvc. But in sailsjs, I do not know where and how to do this due to lack of documentation. 回答1: If you're referring to the ability of Express to bind to a Unix domain socket rather than a port, you can accomplish the same with Sails by setting the port config, either on Sails lift: sails lift --port=/tmp/sails.sock or in your /config/local.js port: '/tmp/sails.sock' Then you could telnet /tmp/sails.sock with Sails

Sails.js API passport.js authentication

流过昼夜 提交于 2019-12-24 03:23:39
问题 I am trying to develop an API backend in Sails.js. The most basic thing which I require is authentication. With that, I found the sails-generate-auth generator, I have followed all the steps listed at sails-generate-auth . Now, when I access http://localhost:1337/register , I see a simple registration form, same goes for login, and after logging in, I see a cookie set in my browser as sails.sid . After inspecting the AuthController.js I see that it has been written for server rendered views.

301 redirect when using SailsJs

浪尽此生 提交于 2019-12-24 03:16:19
问题 Situation: Upgrading an old site that was basic HTML to use SailsJS. Old site has .html extensions and is ranked well in search engines for these results. As such I would like to route all incoming requests from their old URLs (.html extension) to their new results generated via sails (no extension). The best approach seems to be a 301 redirect but I am unsure as the best practices to implement this using a SailsJS based server. www.blah.com/blah2.xml => www.blah.com/blah2. 回答1: You should

Sails Js Read uploaded file content

。_饼干妹妹 提交于 2019-12-24 03:09:38
问题 I want get content from my uploaded file. Uploaded file is just text file and i want read this file line by line req.file("model").upload(function (err, uploadedFiles){ if (err) return res.serverError(err); return res.json({ message: uploadedFiles.length + ' file(s) uploaded successfully!', files: uploadedFiles, content: uploadedFiles[0] // I want to get my uploaded file content // Stream or buffer }); }); 回答1: You can get the file descriptor from uploadedFiles[0].fd Use it to read / stream

SailsJS Schema Name Issue

孤人 提交于 2019-12-24 01:55:23
问题 I am trying to connect my SailsJS app to a postgres db that has another schema aside from 'public' The schema name of the postgres DB that I am connecting to is 'sales' Where am I am going wrong? Thank you! connection: 'postgres', tableName: 'user__c', meta: { schemaName: 'sales' }, attributes: { name: { type: 'string' }, picture_url: { type: 'string' } } 回答1: It's been so long but still, this is still an issue with waterline-sequel (0.5.0) in the latest version of Sails (0.11.x), and it has

How to unsubscribe a socket from a room when socket disconnected from the server

痞子三分冷 提交于 2019-12-24 00:43:36
问题 If socket is disconnected from the server, Will all the subscription of that socket will be removed from the chat-room by default(by sails) or we have to remove it manually(by code) 回答1: Base of socket.io source code this.leaveAll() will run before fire disconnect event. So no need to leave from rooms manually Socket.prototype.onclose = function(reason){ if (!this.connected) return this; debug('closing socket - reason %s', reason); this.emit('disconnecting', reason); this.leaveAll(); // leave

sails.js Sessions - rememberme functionality

 ̄綄美尐妖づ 提交于 2019-12-24 00:43:18
问题 I have been trying to implement rememberme functionality using sails. I want a session to persist until the browser is closed. However, if a rememberme checkbox is ticked when the user logins in I want the session to persist for 30 days. I used the remember me passport strategy from here: https://github.com/jaredhanson/passport-remember-me but it ends up sitting on top of the sails session and the one called first ends up superseding the other. 回答1: You can set the cookie age just before

Sails.js Skipper: How to read the uploaded file stream during upload?

孤街醉人 提交于 2019-12-23 19:19:34
问题 I am using sails version 0.11 which comes bundled with skipper for file uploads. I need to upload big files of over 100 MB in size at least. Now I don't want the file upload to complete before I start further processing of the file on server. I want to read the file stream while it is being uploaded. Here is how I am trying to achieve the same: var csv = require("fast-csv"); bulk: function (req, res){ function parseEntry(entry){ return entry } var inputStream = req.file('employees'); var