sails.js

Sails.js best practice in using transactions with promises (Postgres)

一曲冷凌霜 提交于 2019-12-03 05:02:30
问题 I'm using sails 0.9.16 with Postgres and my question is: what is the best way to execute transaction using current API with promises? May be there is something better than: Model.query('BEGIN TRANSACTION', function (err) { if (err) { next(err); } else { Model .create(...) .(function (value) { return [value, RelatedModel.create(...).then(...)]; }) .fail(function (err) { Model.query('ROLLBACK'); next(err); }) .spread(function (...) { Model.query('COMMIT') next(...); }) } }) Thanks for help! 回答1

Transactional SQL with Sails.js

心不动则不痛 提交于 2019-12-03 03:23:09
So I have been playing with NodeJS/Express for a little with now and I would really like to try to rewrite a relatively large side project using a full JavaScript stack just to see how it will work. Sails.js seems to be a pretty good choice for a NodeJS backend for a REST API with support for web sockets which is exactly what I am looking for however is one more issue I am looking to resolve and that is transactional SQL within NodeJS. Most data layer/orms I have seen on the NodeJS side of things don't seem to support transactions when dealing with MySQL. The ORM provided with Sails.js

Deploying a Sails.js app to Heroku?

梦想的初衷 提交于 2019-12-03 02:25:46
问题 I have limited experience deploying Node.js apps -- how can I deploy a Sails.js app to Heroku? I've heroku login ed and heroku create d my app already. 回答1: You should check out this github repo : heroku-sails It should get you started with sailsjs on heroku There is a discussion around this particular github repo here on the sails.js google group These are also resources that can help you get your app running : Sails Deployment Guide An answer of sails.js author to the same question 回答2: I

Authentication methods over sockets

女生的网名这么多〃 提交于 2019-12-03 01:55:56
I'm trying to get authentication working over sockets with sailsjs and passport . The challenge seems to be the fact that a socket connection doesn't have a session, and that sailsjs mocks a request object, causing it to not have Passport middleware setup. This caused nodejs to throw an error, saying that the req object didn't have a method called logIn . So, I've tried following the code snippet as provided by @xdissent here: Sails.js + Passport.js authentication through websockets which, indeed allows me to sign in without throwing errors. Or does it..? It turns out that it does something ,

Minify all of sails.js served html

空扰寡人 提交于 2019-12-03 01:25:02
I need my sails.js app to serve minified html to the user. So it is hard to read by the user. Has anyone done this before ? Thank you. Marcelo Boeira This works for me: https://github.com/balderdashy/sails/issues/2188#issuecomment-56994236 In config/views.js : var minify = require('html-minifier').minify; var ejs = require('ejs-locals'); var parsing = function(path,options,fn) { options.locals = options.locals || {}; options.locals._layoutFile = 'layout.ejs'; ejs(path, options, function(err, str){ str = minify(str,{collapseWhitespace: true, removeComments: true}); return fn(err, str); }); };

Angular 8 using sails js websokcet (sokcet.io)

早过忘川 提交于 2019-12-02 23:17:12
问题 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,

Sails.js — Accessing local.js environment settings in controllers

与世无争的帅哥 提交于 2019-12-02 18:34:46
In production I have AWS credentials stored as heroku config variables. In development I want to include the config details in config/local.js, but how do I access the config details in a controller? local.js contains: module.exports = { aws_key: "...", aws_secret: "..." } In my controller I have tried aws_key , config.aws_key , and others - but no luck. Is there a main app namespace that I can use to scope into the properties exported by local.js? I am new to sails and I feel like this should be straight forward - any help would be appreciated. Drew Solution found. Step 3 was where I was

npm install not installing latest version on GitHub

你离开我真会死。 提交于 2019-12-02 17:55:09
I have a module called 'sails-mongo' and I want to update it to the newest version using the following command: npm update sails-mongo --save I also tried uninstall then install again. I tried sails-mongo@latest and sails-mongo@beta . Problem : The current version ( master ) on GitHub the package.json ( https://github.com/balderdashy/sails-mongo/blob/master/package.json ) file has: "dependencies": { "async": "~0.2.9", "lodash": "~2.4.1", "mongodb": "1.4.2", "waterline-errors": "~0.10.0" }, And in the one being updated "dependencies": { "async": "0.2.10", "underscore": "1.5.2", "underscore

Deploying a Sails.js app to Heroku?

老子叫甜甜 提交于 2019-12-02 15:56:51
I have limited experience deploying Node.js apps -- how can I deploy a Sails.js app to Heroku? I've heroku login ed and heroku create d my app already. Jérémie Parker You should check out this github repo : heroku-sails It should get you started with sailsjs on heroku There is a discussion around this particular github repo here on the sails.js google group These are also resources that can help you get your app running : Sails Deployment Guide An answer of sails.js author to the same question I want to prevent any confusion for those who are familiar to node deployment on heroku. There are a

Error using custom Skipper body parser configuration

微笑、不失礼 提交于 2019-12-02 15:55:59
问题 I'm using sails version 0.10.5. I have the bodyParser set like so in http.js : bodyParser: require('skipper')({ limit: 52428800 }) And I keep getting this error when starting the server: error: TypeError: Cannot read property 'toLowerCase' of undefined at _parseHTTPBody (/var/www/testapp-backend/node_modules/skipper/index.js:49:19) at /var/www/testapp-backend/node_modules/sails/lib/hooks/http/middleware/defaults.js:104:28 at module.exports (/var/www/testapp-backend/node_modules/sails/lib