sails.js

Handle browser reload socket.io

百般思念 提交于 2019-12-17 10:37:18
问题 There is a way in socket.io to create a timeout in the disconnected event, then check if the user has been reconnected ? The idea is to emit data / save user state in database only if the user is not reconnected after timeout Edit : Followed @Are Wojciechowski answer, I'm done with a multi tabs & F5 flood handler https://gist.github.com/foohey/7696811 回答1: There is a socket.on('disconnect', function () { ... }); . So you can just do socket.on('disconnect', function () { setTimeout(function ()

CRUD blueprint overriding in sails.js

十年热恋 提交于 2019-12-17 02:49:09
问题 According to this closed issue in sails: https://github.com/balderdashy/sails/issues/835 CRUD Blueprint Overrides "absolutely, this is coming in v0.10" I'd like to modify the blueprints in my sailsjs service to allow named roots (consuming in ember). Currently I'm having to customize every controller I create with actions that are largely duplicates of what is already in the blueprints. I suspect that I can move this code out of my controllers now and into a blueprints override area, but I'm

How to serve images in a folder in Sailsjs?

为君一笑 提交于 2019-12-14 04:10:12
问题 How to serve bunch of images in sails.js? Suppose, my API server has a controller for user, to upload images and it's stored in each users' folder in server. // Image upload var userId = req.param('id'); req.file('image').upload({ maxBytes: 2000000, // set custom upload dir path name dirname: require('path').resolve(sails.config.appPath, 'assets/images/', userId) }, function whenDone(err, uploadedFiles){ if (err) { return res.negotiate(err); } // if no file uploaded, response with error if

Sails.js non-static routing urls

非 Y 不嫁゛ 提交于 2019-12-14 03:57:15
问题 So I was working with this Sails.js flash message for user registration but then I got into a new issue. So basically I am using the following in the user controller to render non-static content of the user/register.js file to client. 'register': function(req, res){ res.view(); }, This however means that the address to access the registration page will be http://localhost/user/register . Is it possible to change this url to work with http://localhost/register without webpage redirects

Connect to Sails WebSocket

旧巷老猫 提交于 2019-12-14 03:19:30
问题 I'm triying to develop a simple Hello World Websocket using Sails framework V0.12. I need to connect an external Basic Front-End (HTML,CSS,JS) to that Sails WebSocket server. Send a simple event and retrieving 'Hello World!!' I'm using Sails API sails.io.js. I have tried this in Front-End <!doctype html> <html> <head> <script type="text/javascript" src="js/dependencies/sails.io.js"></script> <script type="text/javascript"> window.onload = function() { io.sails.url = 'http://localhost:1337';

Sails.js- how to move the Top nav to a component?

夙愿已清 提交于 2019-12-14 03:04:25
问题 I needed a top-nav with a good amount of extras and flexabliltiy. I also didnt want my layout.ejs to become a tangled mess. So I moved my top-nav into a component and wanted to share how I did it here. 回答1: Create a new component in assest/js/components/ (I look at the existing components that come with the Sails app for reference) I named mine masthead Built my nav-bar in the component Removed any mention of the top-nav in layout.ejs 
 Added <masthead></masthead> to all HTML files that will

Elasticsearch: how can i create mapping before upload json data into Elasticsearch

混江龙づ霸主 提交于 2019-12-14 02:32:26
问题 I'm trying to create mapping before uploading json data into elasticsearch. I don't know how to implement mapping before uploading json data in sails.js This is my bulkupload snippet var body = []; //row is json data rows.forEach(function(row, id) { body.push({ index: { _index: 'testindex', _type: 'testtype', _id: (id+1) } }); body.push(row); }) client.bulk({ body: body }, function (err, resp) { if (err) { console.log(err); return; } else { console.log("All Is Well"); } }); I want to create

Populating multiple tables in sails waterline orm

China☆狼群 提交于 2019-12-14 01:52:59
问题 I am working on a sails applications which contains multiple(>2) tables which I need to join with the help of populate method e.g. Category.js model attributes: { CategoryID:{ type:"integer", required:true, primaryKey:true, autoIncrement:true }, SubCategories:{ //REFERING TO SUB-CATEGORY TABLE collection:'SubCategory', via:'CategoryID' }, CategoryName:{ type:"string", required:true, maxLength:50 } } this is SubCategory.js model . attributes: { id:{ type:'integer', required:true, primaryKey

Sails.js: how to Join multiple models using waterline?

核能气质少年 提交于 2019-12-14 01:19:14
问题 I've 3 models Continent,Country and city. I'd like to join these models to get the results. Continent.js attributes: { continent_Id:{ type:'string', primaryKey: true }, continent_Name:{ type:'string' }, description:{ type:'string' }, country:{ collection: 'country', via: 'continent' } } Country.js attributes: { country_Id:{ type:'string', primaryKey: true }, countryName:{ type:'string' }, description:{ type:'string' }, continent:{ model:'continent' }, languages:{ collection:'Country_language'

Sails js - waterline ORM limit or sort after group by?

眉间皱痕 提交于 2019-12-14 00:45:50
问题 I am using Waterline ORM for sails.js. limit and sort are not working when you use groupby , but are working fine when you dont do any grouping . For example Model.find({ groupBy:['term'], sum:['count'], limit:20, sort :'count DESC'}).exec(function(error,response){ if(error) res.json(error); res.json(response); }); 回答1: Use Model.find() .groupBy('term') .sum('count') .limit(20) .sort({count: 'desc'}) .exec(function (err, data){ //Your code here.. }); 回答2: Example override toJSON // Your Model