sails.js

Sails.js authorization for socket requests

若如初见. 提交于 2019-12-04 03:44:54
I'm trying to build a chat application based on sails.js. The url for messages from a specific chat looks like this: /api/chat/:id/messages When I request this url with XHR, it provides a session cookie and sails.js builds a session object. I can easily check user rights to read the messages from the specific chat. However, I need to request this url with socket.io so that the client can subscribe to all future changes of the messages collection. When I request this url with socket.io, no session cookie is set and the sails.js session is empty. So, I cannot check the user rights on the server

How to render a view into a string in SailsJS?

让人想犯罪 __ 提交于 2019-12-04 03:42:01
问题 In one controller I want to render a certain view with a certain layout to send an email with the resulting string, but I obviously do not need to show the result to the user. Is there a way to use the EJS engine that I'm using to render views to achieve this? Here's my a bit simplified controller action: setEmail: function(req, res) { var update = { activationToken: _getToken(), email: req.param('email') }; Profile.update(res.locals.profile.id, update).then(function(profile) { res.redirect

Change sails.js EJS views to use .html extensions instead of .ejs extensions?

痞子三分冷 提交于 2019-12-04 03:39:39
问题 Is it possible to configure sails.js apps to use .html extentions rather than .ejs (but still use the ejs view engine )? sails new app creates ./views/home/index.ejs and ./views/layout.ejs . I'd like to change the extensions to .html but keep everything else working the same way. ie: I would now have ./views/home/index.html and ./views/layout.html , and the home page would still be injected into the layout page, as per normal. How can I configure this please? 回答1: In your config/views.js :

How to maintain multiple API versions in sails.js

可紊 提交于 2019-12-04 03:35:01
Does anyone have ideas on maintaining multiple versions of your API when using sails.js? Imagine a simple example like: // Request GET /api/v1/catVids?min_view_count=10000 // Response [{"video_title": "top cat fails"}, {"video_title": "funny-ass cats"}] Users are actively consuming v1 of the API but something has now changed in the requirements that will break existing functionality. For example, an attribute name change. So now we need to utilize a different controller to fulfill requests for this new behavior. What I would like to do is have both APIs co-exist so backwards compatibility is

Is it possible to use the Mocha Framework against a model in Sails.js?

拟墨画扇 提交于 2019-12-04 03:30:41
Sails.js uses the MVC pattern for Node.js and I was wondering if Mocha could be hooked up for testing Models. I know you asked this awhile ago, but I was searching around myself and there's not much out there at the moment. I figured I'd drop what I found into this answer... I found some discussion on the sails github and a gist with some example code. There is also a second discussion with more examples. Check out wolfpack . It's a SailsJS model-testing library that allows you to test Sails models without the need for a db or lifting your sails app. 来源: https://stackoverflow.com/questions

Sailsjs Socket IO

你。 提交于 2019-12-04 03:29:26
I am new to SailsJs and Socket IO. I want to execute the below Socket IO example in Sailsjs. In the server side, I need to execute the following code. But I dont know where to place this code. var io = require('socket.io').listen(80); io.sockets.on('connection', function (socket) { socket.emit('news', { hello: 'world' }); socket.on('my other event', function (data) { console.log(data); }); }); I am aware that I can place this inside the Cntroller's function but it will add listener to every request which I dont want. Client Side: var socket = io.connect('http://localhost'); socket.on('news',

Unique property fails in Sails.js

送分小仙女□ 提交于 2019-12-04 02:53:28
问题 The following code represents an Account Model in Sails.js v0.9.4 . module.exports = { attributes: { email: { type: 'email', unique: true, required: true }, password:{ type: 'string', minLength: 6, maxLength: 15, required:true } } }; When I send two POSTS and a PUT request via Postman to localhost:8080/account, the unique property of the email fails. Specifically, I send the following HTTP requests from Postman: POST http://localhost:8080/account?email=foo@gmail.com&password=123456 POST http:

Is it possible to rename `createdAt` and `updatedAt` in sails.js / waterline

こ雲淡風輕ζ 提交于 2019-12-04 02:34:00
Using Waterline ORM from SailsJS, my defaults for autoCreatedAt and autoUpdatedAt are set to false, but I still need to implement to the functionality just using different field names (DBA request). Is there a way to either: specify different column names for the automatically generated field, or manually emulate the same behave in an attribute definition, or can I just leave custom fields in the schema like created_ts and updated_ts to be updated with triggers in the DB schema itself (but I still need Waterline to read them)? Thanks in advance. Tristan Foureur I just opened two pull requests

How to use “await” in sails when creating a new record

送分小仙女□ 提交于 2019-12-04 01:53:03
问题 I want to use "await" According to the sails documentation I act as follows: https://sailsjs.com/documentation/reference/waterline-orm/models/create create: function (req, res, next) { var new_place = await Place.create({...}, function place_created(err, XX){ if(err && err.invalidAttributes) { return res.json({'status':false, 'errors':err.Errors}); } }).fetch(); if(new_place){ console.log(new_place); res.json({'status':true,'result':new_place}); } }, But I get the following Error: var new

Using sails.js with an existing postgres database

无人久伴 提交于 2019-12-04 00:30:35
I was looking at using Sails for an app that we are developing. I'm using the sails-postgresql adapter which uses the waterline orm. I have an existing database that I want to connect to. If I create a model using generate something and then in my model I have attributes:{ title:{type:'String'} } If I browse to localhost/something the orm deletes all the columns in the something table except title. Is there a way to stop it from doing this? This app should not delete columns on this database. Thanks! I am the author of Sails-Postgresql. Sails has an ORM called Waterline that it uses for