sails.js

Handling production/dev/testing configs in sails.js

强颜欢笑 提交于 2019-12-09 15:14:30
问题 Does anyone know the best way to handle prod/dev/test config switching in sails? I really like how actionhero.js automatically loads config/environment/{env}.js based on the contents of NODE_ENV but I don't see a built-in way to do something similar in sails. I noticed that sails will load any file in config/ during server bootstrap so my hacky solution for now is to setup the following: config/ |-- local.js |-- environment/ |---- production.js |---- staging.js |---- development.js |----

How to access external api using sails.js?

爱⌒轻易说出口 提交于 2019-12-09 13:32:34
问题 I am trying to access information from facebook within a controller using sails.js. Here is my code: module.exports = { commonLikes : function(req,res){ var other_uid = req.param('uid'); //var me = req.params.user.uid; console.log(other_uid); User.findOne({uid : other_uid}).done( function(err,data){ var other = data; var http = require('http'), options = { host : "https://graph.facebook.com", port : 80, path : "/"+other.uid+"/likes?access_token="+other.token, method : 'GET' }; var webservice

Add express middleware for param validations

天大地大妈咪最大 提交于 2019-12-09 10:55:12
问题 In a sails.js application is there a simple way of including express-middleware ? For instance extending the request object with express-validator . 回答1: Adding express-middleware in a sails application is simple. create a new policy. policies |_ middleware.js / .coffee Add Express Middleware YOUR_MIDDLE_WARE_FILE_NAME.js Inside your middleware file we create the standard export for node.js module.exports = require('middle-ware')(OPTIONS_GO_HERE) // See middleware docs for configuration

How can I write sails function on to use in Controller?

假如想象 提交于 2019-12-09 01:43:58
问题 I have a question on sails js: How can I write sails function on model To use in Controler? like: beforeValidation / fn(values, cb) beforeCreate / fn(values, cb) afterCreate / fn(newlyInsertedRecord, cb) 回答1: If you are actually trying to use one of the lifecycle callbacks, the syntax would look something like this: var uuid = require('uuid'); // api/models/MyUsers.js module.exports = { attributes: { id: { type: 'string', primaryKey: true } }, beforeCreate: function(values, callback) { //

Dynamic database connection in Sails Js

六月ゝ 毕业季﹏ 提交于 2019-12-08 20:52:47
问题 How I can set a database connection from a controller?. I need to specify in the controller the type of database , user, password, port, database name and set this in connections.js. 回答1: You could probably modify the sails.config.connections global and edit an existing connection. Of course this would only last until the app is restarted. If you want to make it more permanent but not modify config js files you could then save the connection details on a localdb (sails-disk?) and re-set the

Sailsjs Geospatial Solution with Waterline

喜你入骨 提交于 2019-12-08 19:25:06
问题 It seems like Sailsjs/Waterline does not currently support a POINT type or geospatial indexing with JSON. Are there any ways to customize a schema for certain adapters to support geospatial datatypes? If not, is there a way to integrate a second ORM into Waterline that does so? 回答1: In Sails.js, you need MongoDB (npm install --save sails-mongo) for geospatial indexing, plus you need to ensure the 2dindex gets created in config/bootstrap.js as such (make sure to replace modelname and

nginx / sails.js: incomplete file upload

老子叫甜甜 提交于 2019-12-08 19:12:34
We are developing an app using sails.js. In this app we have an upload controller: https://github.com/makinacorpus/mnhn_bai/blob/master/api/controllers/Object3DController.js This controller use skipper under the hood, as explained in the documentation. Now the problem is that when we upload big files, they are incompletely stored, the uploaded size is never the same and varies from 7mb to 14mb for a 15 mb file. The architecture is as follow: haproxy -> nginx -> node.js/sails. If we replace the nginx reverse proxy by a simple apache + proxypass configuration, the uploads work flawlessly. If we

Securing a nodejs / sailsjs API with OAuth2

爱⌒轻易说出口 提交于 2019-12-08 17:45:45
问题 I have developed a REST API with sailsjs and I'd like to add OAuth2 authorization to secure this API. I'm quite new to OAuth and I'm not sure where to start. I found several modules that could be used for this purposes, for instance oauth2orize and an example of its usage https://github.com/aaron524/sails-oauth2-provider-example but I do not fully understand how this is working internally. Basically, I'll have several clients consuming the API I'm developing: - clients that I trust and that I

Multiple model updates in sails waterline

杀马特。学长 韩版系。学妹 提交于 2019-12-08 13:50:48
问题 I'm building a project on sails (0.10.0-rc5) for a few days and in a few cases i need to update multiple entries at once with the same data so I made something up ... Servers.find({owner_id: anonymous_user.id}).exec(function(error, servers) { catches.error(error); queries.save_each(servers, {owner_id: user.id}); }); The interesting part is queries.save_each() which I created ... /** * Save each ActiveRecord objects with the desired attributes * @param {object} objects ActiveRecord object (e.g

Error installing SailsJS in OpenShift

情到浓时终转凉″ 提交于 2019-12-08 11:20:57
问题 info: Starting app... Grunt :: module.js:340 throw err; ^ Error: Cannot find module '/var/lib/openshift/54a3a0ec4382ecf1130000f1/app-root/runtime/repo/node_modules/sails/node_modules/grunt-cli/bin/grunt' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:902:3 回答1: OpenShift needs grunt separately added to package.json, it does not contain it out of box. Try to