sails.js

How to handle async concurrent requests correctly?

断了今生、忘了曾经 提交于 2019-11-29 00:44:48
Let's say I have some sort of game. I have a buyItem function like this: buyItem: function (req, res) { // query the users balance // deduct user balance // buy the item } If I spam that route until the user balance is deducted (the 2nd query) the user's balance is still positive. What I have tried: buyItem: function (req, res) { if(req.session.user.busy) return false; req.session.user.busy = true; // query the users balance // deduct user balance // buy the item } The problem is req.session.user.busy will be undefined for the first ~5 requests. So that doesn't work either. How do we handle

How to connect with mongodb using sailsjs v0.10?

家住魔仙堡 提交于 2019-11-28 22:10:56
问题 Now Using sailsjs v0.10 . Configure connections.js and models.js and change it to connection: 'localMongodbServer' ,installed npm install sails-mongo. Aftet all this it shows error var des = Object.keys(dbs[collectionName].schema).length === 0 ? ^ TypeError: Cannot read property 'schema' of undefined at Object.module.exports.adapter.describe (app1_test/node_modules/sails-mongo/lib/adapter.js:70:48) If change collections.js to adapter.js shows error [err] In model (model1), invalid connection

Swagger Sails JS

我的未来我决定 提交于 2019-11-28 20:39:21
Any idea of how to integrate swagger , swagger-ui with a sails js project? Where can i found information about it, or about another way to comment an api generated with sails? Thanks! I was searching for a solution for this a little over a week ago, but I found the information scattered a bit. Here's how I integrated swagger and swagger-ui with my sails 0.11.x project. 1. Install sails-swagger npm install --save sails-swagger This provides a hook that will dynamically generate the swagger document. Unfortunately, it's only compatible with sails 0.12.x (which is an rc at the time of this post).

How to use Sequelize in SailsJs

戏子无情 提交于 2019-11-28 19:20:05
问题 Waterline is an excellent ORM but I noticed that there are many features that are not present yet on waterline but Sequelize already have. So I have decided to switch to sequelize but still using Sails for the others things. I have search tutorial how to switch to sequelize but nothing. How can I replace Waterline for sequelize in sails Js? 回答1: I've moved forward with sequelize as well, there are two project that came out really recently, so i would like to announce them. sails-hook

Sails.js - How to inject a js file to a specific route?

假如想象 提交于 2019-11-28 17:59:33
For example, I have a page /locations/map which I need to include Google Map library, and include a .js file (e.g. location.js) specifically for this page only. I want to inject these 2 files to after <!--SCRIPTS END--> this line Is it possible to do this? NOTE: I was using Sails.js v0.10 Sails uses ejs-locals in its view rendering, so you can accomplish what you want with blocks. In your layout.ejs file, underneath the <!--SCRIPTS END--> , add (for example): <%- blocks.localScripts %> Then in the view you're serving at /locations/map , call the block with your script tag, for example: <%

Create config variables in sails.js?

会有一股神秘感。 提交于 2019-11-28 16:20:54
I'm converting an app of mine from Express to sails.js - is there a way I can do something like this in Sails? From my app.js file in Express: var globals = { name: 'projectName', author: 'authorName' }; app.get('/', function (req, res) { globals.page_title = 'Home'; res.render('index', globals); }); This let me access those variables on every view without having to hardcode them into the template. Not sure how/where to do it in Sails though. ataman You can create your own config file in config/ folder. For example config/myconf.js with your config variables: module.exports.myconf = { name:

how to use sails.io.js version 0.11.3 in node server

◇◆丶佛笑我妖孽 提交于 2019-11-28 14:38:52
I would like to create a chat application in my sailjs based project, How and where can i configure the socket and related setting in the server ? I got a sample project from this repository but it is using sails v0.10 and i need to use sails v0.11.3, but v0.11.3 having many changes while using socket in Nodejs script, for example, We can't use onConnect since it is deprecated. I have tried this example, but not working this with sail v0.11.3 https://github.com/sgress454/sailsChat This is the code i have done, but i don't know where should i put , it is not working when i put this in sockets

How to properly do a Bulk upsert/update in MongoDB

陌路散爱 提交于 2019-11-28 13:30:27
I'm trying to: Find a document according to a search criteria, If found, update some attributes If not insert a document with some attributes. I'm using a Bulk.unOrderedOperation as I'm also performing a single insert. And I want to do everything in one operation againast DB. However something it's causing nothing is being inserted for the update/upsert operation. This is the insert document: var lineUpPointsRoundRecord = { lineupId: lineup.id, // String totalPoints: roundPoints, // Number teamId: lineup.team, // String teamName: home.team.name, // String userId: home.iduser, // String

Node.js Web Application examples/tutorials [closed]

最后都变了- 提交于 2019-11-28 13:13:57
问题 So I finished watching Douglas Crockford's excellent series on Javascript, and in the final episode (so far), loopage he lays out why Node.js is a near perfect solution for server side code. He talks about keeping state, not in the database, but in closures running in Node.js, he also states that templating systems (like JSP, PHP, and ASP) are a poor abstraction for more complicated Web Applications and that node.js provides a solution to this. And I am ready to buy in, but I can't find any

Correct way of handling promisses and server response

♀尐吖头ヾ 提交于 2019-11-28 13:07:15
I am trying to improve my code in node.js / sail.js and I am fighting server response in promisses. When you look at the first .then function you can see that method returns false in case of forbidden access or notFound . Then, in the next .then functions I must check if the return type is === false to skip to section and avoid sending http headers twice. Can this be improved somehow, to skip all next .then methods in case of failure? I can throw an Exception to go in the last .catch but then there must be a case to switch between all possible states. (i.e. forbidden, serverError or even not