sails.js

Installing a another Sails.js version locally

此生再无相见时 提交于 2019-12-05 21:19:33
I've installed Sails.js version 0.9.13 globally on my Mac which runs fine, but I'm trying to fiddle with the 0.10.0-rc4 locally in a folder. Running sudo npm install sails@beta seems to work fine; my node_modules/package.json says "version": "0.10.0-rc4" But when I run sails new testProject in that folder, the generated testProject/package.json says "sails": "0.9.13" . I know that I could just change the testProject/package.json to "version": "0.10.0-rc4" and then npm install but that doesn't work. What am I doing wrong? How could I fix this? Basically, you can just run ./node_modules/sails

Call REST API in Sails js

流过昼夜 提交于 2019-12-05 20:50:50
Im using Sails js. I dont know how to call a REST api and get the response data. My Controller: var request = require('request'); var http = require('http'); var https = require('https'); module.exports = { main: function(req, res){ var rs = "Someone"; var options = { hostname: 'thomas-bayer.com', port: 80, path: '/sqlrest', method: 'GET' }; http.request(options, function(response) { sails.log.debug('log:'+response); rs = response; }); res.send("Hello "+ rs); } }; I cant get the response data, the sails.log.debug() didnt show anything on the console. It only shows "Helo Someone" on the browser

Disable user hook in sails

不想你离开。 提交于 2019-12-05 19:39:39
I'm using sails on a project hosted on Heroku. I have a web process running a sails web server and a worker process using the same Models as the ones used by the web server. In order to make it possible I have different way to start each process with the same code : the app.js standard way a worker.js file that starts the same sails app with only the orm and services hook activated. However I have added some user hooks in a api/hooks folder that I don't want the worker to start. Is there an easy way to disable those hooks? I tried to lift sails with a { "userhookname" : false } passed in

{ [FacebookTokenError: This authorization code has been used.]

烂漫一生 提交于 2019-12-05 19:12:13
I have a sails app. I was trying to implement Facebook Login. When I click on the Login with facebook button i am getting this error: error: A server error occurred in a request: error: FacebookTokenError: This authorization code has been used. Full error log looks like this: error: A server error occurred in a request: error: FacebookTokenError: This authorization code has been used. at Strategy.parseErrorResponse (/home/node_modules/passport-facebook/lib/strategy.js:198:12) at Strategy.OAuth2Strategy._createOAuthError (/home/node_modules/passport-facebook/node_modules/passport-oauth2/lib

Can certain URLs be exempt from CSRF in sails.js?

心不动则不痛 提交于 2019-12-05 18:36:29
I'm setting up Stripe to work with my sails.js server, and in order to use Stripe's webhooks, I need to disable CSRF for the URLs I provide to Stripe. Is it possible to make certain URLs exempt from CSRF POST requirements in sails.js? The only configuration I can find for CSRF is to turn it on globally, and looking through the source code for the csrf hook ( https://github.com/balderdashy/sails/blob/master/lib/hooks/csrf/index.js ) it looks like if I try to provide a custom object, it just gets replaced with the global settings anyway. Thanks So Murcho's solution is working but actually, sails

Sails.js Waterlock /auth/register causes error 500

蓝咒 提交于 2019-12-05 16:26:01
In trying to make Waterlock not to create new user on login. When I set createOnNotFound to false and try to use http://localhost:1337/auth/register?email=a@s.d&password=12345678 to register a new user. I've got 500 error: error: Sending 500 ("Server Error") response: TypeError: undefined is not a function at Object.module.exports (D:\temp\sails-waterlock\node_modules\waterlock\lib\controllers\actions\register.js:25:44) at bound (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\node_modules\lodash\dist\lodash.js:729:21) at routeTargetFnWrapper (C:\Users\sandres\AppData\Roaming\npm\node

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

本小妞迷上赌 提交于 2019-12-05 15:09:10
问题 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

Using sails.js with an existing postgres database

筅森魡賤 提交于 2019-12-05 14:48:38
问题 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.

How can I access my models in sailsjs outside a controller?

浪子不回头ぞ 提交于 2019-12-05 14:32:57
I have a controller that looks like this. module.exports = { readbyslug: function (req, res) { var slug = req.param('id'); Store.findOneByName(slug.split('-').join(' ')) .then(function(err, store){ if(err) res.send({status:'error', msg:'no store'}); res.send(store); }); } }; however, I would rather not have all this login in the controllers, I would rather stick them in another module. My question is, how do I access the models? are they global or something? Chadams-- models are global by default. So if you did sails generate model foo , you could access Foo in your code. If you'd rather not

sails.js + mocha + supertest + sinon: how to stub sails.js controller function

僤鯓⒐⒋嵵緔 提交于 2019-12-05 14:17:05
I am trying to stub a sails controller function, but I don't know which object to stub. using sinon.stub(object,'funcname', function()... This is probably related to the way sails bind controller functions... Here is some code to give example Controller file api/controllers/PersonController.js var fs = require('fs'); // // I want to stub retrieveData function when testing // function retreiveData(cb) { fs.readFile('./filedata', function (err, data) { if (err) throw err; cb(data.toString()); }); }; function showdata(req, res) { var stack = new Error().stack console.log( stack ) retreiveData