sails.js

Trying to broadcast socket.io message to all connected sockets in e.g. room

a 夏天 提交于 2019-12-02 14:53:22
问题 Challenge: I would like to use SailsJS , and be able to join a room, by means of socket.io, and receive unsolicited messages from this room, not just when one enters or leaves the room but also receive objects. So several clients connect to the server. Afterwards broadcast (initiated from the server) messages/objects to every room and thus everey connected socket in this room. I maybe could just send every connected socket a message, but dearly would like a example on how to do this with

Sails blueprints lifecycle

风流意气都作罢 提交于 2019-12-02 14:08:21
问题 I need to add some additional data to result of find blueprint. I found this solution: module.exports = { find: function(req, res) { return sails.hooks.blueprints.middleware.find(req, res); } } but I can`t find any way to change response here, or add callback into the blueprint. I even try to change blueprint and add the cb in it: module.exports = function findRecords (req, res, cb) { ... if (typeof cb === 'function') res.ok(cb(result)); else res.ok(result); but in this case it returns 500

sailsjs use mongodb without ORM

拥有回忆 提交于 2019-12-02 12:29:33
I want to use mongodb with sails but without any ORM. So below is my service to connect mongodb. Service: //DbService.js const MongoClient = require('mongodb').MongoClient; module.exports = { db:function(req, res){ var connect=MongoClient.connect("mongodb:***********").then(function (err, database) { if(err) console.log(err); else{ database=database.db('*****'); return connect; } }); } } After connection i have called it in controller, But getting TypeError: Cannot read property 'then' of undefined. controller: //HomeControlelr.js module.exports = { index:function(req, res){ DbService.db()

Sailsjs Mysql ORM multiple query on the same table field

本小妞迷上赌 提交于 2019-12-02 11:32:49
问题 Im using sails v 0.10.5 and latest sails-mysql I have a Restaurant filtering system Venue.find().populate('comments', { deleted: false }).where({ restaurant_services: {contains: '"delivery":1'}, restaurant_services: {contains: '"takeout":1'}, restaurant_specialties: {contains: '"breakfast":1'} }) Now the problem is when I get the data from the client, I do not know how many items the user has selected for restaurat_services, so obviously I have to create a dynamic JSON object for the .where()

Sails.io.js io.socket.get('/user',…) Not implemented in core yet

别说谁变了你拦得住时间么 提交于 2019-12-02 10:54:59
Create e.g. assets/js/dependencies/app.io.js with: io.socket.on('connect', function socketConnected() { console.debug("This is from the connect: ", io.socket); console.debug("WebSocket is connected:", io.socket.isConnected()); io.socket.get('/user', function(resData) { console.debug(resData); }); }); Console |> Now connected to Sails. \___/ For help, see: .... (using sails.io.js browser SDK @v0.13.7) app.io.js:3 This is from the connect: SailsSocket {headers: undefined, eventQueue: Object, isConnecting: false, extraHeaders: Object, hostname: "localhost"…} app.io.js:4 WebSocket is connected:

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

此生再无相见时 提交于 2019-12-02 10:17:11
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' }, dateManuf: { required:true, date:true } }, beforeValidation:function(values, next) { /* I want to

Angular 8 using sails js websokcet (sokcet.io)

倖福魔咒の 提交于 2019-12-02 10:13:31
I want to connect angular 8 in front to sails js in backend through websocket. but my code doesn't work. may someone help on way in backend i just did following: in controller: /** * SocketController * * @description :: Server-side actions for handling incoming requests. * @help :: See https://sailsjs.com/docs/concepts/actions */ module.exports = { subscribe: function(req, res) { if( ! req.isSocket) { return res.badRequest(); } console.log('here is socket'); // sails.sockets.join(req.socket, 'feed'); // var roomName = req.param('roomName'); var roomName = 'feed'; sails.sockets.join(req,

Confusion about web-application ports

霸气de小男生 提交于 2019-12-02 10:11:31
问题 I have a project that is already deep in development, and there is a problem with the ports. The Client is SPA written in backbone, that uses Sails as a server. Problem is in the fact that Client is running in Express on port 80, while Sails is run on 1337. I would like to host this backbone application within the Sails, not ouside the sails. A bit more details: When I fire the Fiddler, I am seeing requests being made to localhost:1337/get/user. I need it to reside on port 80 as well.

Trying to broadcast socket.io message to all connected sockets in e.g. room

若如初见. 提交于 2019-12-02 10:11:26
Challenge: I would like to use SailsJS , and be able to join a room, by means of socket.io, and receive unsolicited messages from this room, not just when one enters or leaves the room but also receive objects. So several clients connect to the server. Afterwards broadcast (initiated from the server) messages/objects to every room and thus everey connected socket in this room. I maybe could just send every connected socket a message, but dearly would like a example on how to do this with SailsJS 0.10, and a elegant method in the SailsJS 0.10 way. I am looking at : https://github.com

Sails.js Download File To Client

爱⌒轻易说出口 提交于 2019-12-02 09:48:04
问题 In my Sails.js(v0.12) app we generate a file into the myApp/downloads/uuid-filename.ext. However I cannot find a solid answer on how to download the file to client. My first idea was to pass the uuid to the user and allow them to download it from the URL. However I'm unsure how to access the files from the client even if I know the full file name. The second idea was to stream the content to the user, but without the Express.js "res.download()" function it seems impossible. I found "res