sails.js

Sails.js v 10.2 missing express app

ε祈祈猫儿з 提交于 2020-01-01 10:47:08
问题 How can we access express app instance from Sails global object after upgrade? When in sails.0.9x we can access express app instance by sails.express.app after upgrading to 0.10, the express function is missing How can we call the app? Our test case failed since using supertest, how can we fixed the sails.express.app problem var request = require("supertest"); describe("TestController", function() { describe(".plain", function () { it("returns 200 with status done", function(done) { request

Sails.js authorization for socket requests

浪子不回头ぞ 提交于 2020-01-01 09:15:13
问题 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

Sailsjs Socket IO

雨燕双飞 提交于 2020-01-01 08:55:48
问题 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

Accessing config variables from other config files

核能气质少年 提交于 2020-01-01 08:38:17
问题 I am having problems using in a config file a config var set in another config file. E.g. // file - config/local.js module.exports = { mongo_db : { username : 'TheUsername', password : 'ThePassword', database : 'TheDatabase' } } // file - config/connections.js module.exports.connections = { mongo_db: { adapter: 'sails-mongo', host: 'localhost', port: 27017, user: sails.config.mongo_db.username, password: sails.config.mongo_db.password, database: sails.config.mongo_db.database }, } When I

Sailsjs - How to use mySQL

我的梦境 提交于 2020-01-01 07:04:42
问题 How to use mysql with Sails ? Also, if I change the database to a mySQL one, do I lose all my current model data ? I spent some time looking for tutorials and demos but haven't found any. 回答1: In order to use mySQL with sails, you will have to: Define an adapter in config/adapters Example adapters file: module.exports.adapters = { 'default': 'disk', disk: { module: 'sails-disk' }, 'mysql-adapter': { module: 'sails-mysql', host: 'HOST', user: 'USER', password: 'PASSWORD', database: 'DATABASE'

How do I namespace my api in sails.js like so /api/v1?

独自空忆成欢 提交于 2020-01-01 05:38:47
问题 I want to namespace my api requests to /api/v1/ Maybe later some also to api/v2/. How can I do this efficiently in sails.js? 回答1: There is three ways of doing this. 1st: blueprints http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.blueprints.html how to create a global route prefix in sails? prefix: '/api' or restPrefix: '/api' how to create a global route prefix in sails? 2nd: in each controller adding _config: { prefix: '/api/v2' } 3rd: configure it in the routes http:

How to Log in SailsJS

十年热恋 提交于 2020-01-01 04:08:08
问题 What is the actual syntax to log in SailsJS? Docs don't have anything, but found the following line in the site's roadmap "Pull out Sails.log (winston wrapper) as a separate module so it can be used by waterline" I image it's something like: Sails.log(...) Sails.error(...) Sails.warn(...) 回答1: In your controllers, models, services, and anywhere else that the sails global is available, you can log with one of: sails.log(); sails.log.warn(); sails.log.info(); sails.log.debug(); sails.log.error(

Is it possible to access a session variable directly in a Model in SailsJS

倾然丶 夕夏残阳落幕 提交于 2019-12-31 05:44:26
问题 I have a situation where I'd like to use Sails' create blueprint on a Model. However, I need to access a session variable on that create: URL: /api/myModel/create [post] Model: module.exports = { adapter: 'mongo', schema: true, attributes: { user: { model:'user', required:true, index:true }, item: { model:'item', required:true, index:true }, quantity: { required:true, type: 'integer', defaultsTo: 1, min: 0 }, size: { required:true, type:'string' }, container: { required:true, type:'string' },

How to select document by id with Sails-mongo?

可紊 提交于 2019-12-31 03:25:27
问题 User.find({ _id: { '!': user.id } }, function foundFriends (err, friends) { if(err) return next(err); res.view({ friends: friends }); }); MONGODB : { _id: ObjectId("53b942f7c8638f7b17670acc"), name: "PH", admin: true, online: false, encryptedPassword: "$2a$10$PjcPRgL67ZSOWDjmEwTkvu30xKeDXdCwgZ.D0.bjyDRw9sOfS/4UK", createdAt: ISODate("2014-07-06T12:37:11.522Z"), updatedAt: ISODate("2014-07-09T18:22:47.25Z") } This Code doesn't work, I would like to select document by Id. I don't know what I

Sails.js/Waterline populate deep nested association

被刻印的时光 ゝ 提交于 2019-12-30 17:22:28
问题 I understand that there is no built-in way in Sails.js/Waterline of populating deep nested associations yet, so I am trying to use bluebird promises to accomplish that but I'm running into a problem. I'm successfully retrieving the user, and all the posts (populated with the images collection) associated with it (console.log shows me that everything is filled properly). However, when I override the property "post" of the user and try to assign the fully populated posts retrieved before, it