sails.js

Authentication is returning “401 (Unauthorized)” when it shouldn't

一世执手 提交于 2019-12-12 08:51:02
问题 I am setting up an authentication functionality for my first time and am getting some unexpected results after a user has been logged in. A colleague has given me an application with working authentication to model my application after and it seems like everything I have done is correct. I am using AngularJS on the front-end, SailsJS back-end framework, and PassportJS authentication middleware. My source is (for now) stored publicly... the backend API is on Github here (API Github) and the

Keep Object In Memory Between Requests with SailsJS/ Express

半世苍凉 提交于 2019-12-12 08:45:10
问题 I'm building a server using SailsJS (a framework built on top of Express) and I need to keep an object in memory between requests. I would like to do this because loading it to/ from a database is taking way too long. Any ideas how I could do this? Here's my code: var params = req.params.all(); Network.findOne({ id: params.id }, function(err, network) { if(network) { var synapticNetwork = synaptic.Network.fromJSON(network.jsonValue); if(synapticNetwork) { ... Specifically, the fromJSON()

How to maintain multiple API versions in sails.js

独自空忆成欢 提交于 2019-12-12 08:35:11
问题 Does anyone have ideas on maintaining multiple versions of your API when using sails.js? Imagine a simple example like: // Request GET /api/v1/catVids?min_view_count=10000 // Response [{"video_title": "top cat fails"}, {"video_title": "funny-ass cats"}] Users are actively consuming v1 of the API but something has now changed in the requirements that will break existing functionality. For example, an attribute name change. So now we need to utilize a different controller to fulfill requests

How to show queries in console log using sails?

血红的双手。 提交于 2019-12-12 08:21:56
问题 I am starting a project with sails and mysql, and I do'nt know how configurate it to show the queries executed in the console. 回答1: Unfortunately this isn't possible with Sails at this time, although the feature has been requested. Your best bet is to inspect the log file provided by your database: Postgres: How to log PostgreSQL queries? MySQL: Log all queries in mysql MongoDB: MongoDB logging all queries 回答2: The mysql adapter has a debug variable LOG_QUERIES to send all queries to the

Sails.js model - insert or update records

核能气质少年 提交于 2019-12-12 07:49:56
问题 Been trying out Sails.js and I'm writing an app that imports data from a third-party API and saves in into a MySQL table. Basically I'm trying to sync data over to my app for further analysis, updating my records or creating new records as needed. I've looked through Sails' API and I see methods to find, create and update records but no built-in method to insert/update records based on the situation. Did I overlook something, or will I need to implement this myself? If I have to implement

How to create a normal sails model without being in the models folder

蹲街弑〆低调 提交于 2019-12-12 07:44:11
问题 So, I'm in the middle of implementing a plugin api for my application, and the plugins can have their own models, imagine this. SimplePlugin = { pluginName: 'simple', pluginConfig: {}, SimpleModel: { attributes: { name: 'string' } } } So I need to be able to create the "one-time" model with a function whenever it's needed, it needs to have exactly the same functionality as other models so you automatically get the urls like /simplePlugin/:id for find ..etc Thanks 回答1: What are you trying to

Sails.js session undefined on page refresh

纵然是瞬间 提交于 2019-12-12 05:28:48
问题 In my sails.js application i am setting up session like this req.session.userId="hello"; console.log(req.session.userId); after the first request i hide this line req.session.userId="hello"; after that console.log(req.session.userId) returns undefined 回答1: Tough without seeing more of your controller code, but the session property you are setting is only going to be processed into session upon completing the controller action - e.g. returning a view or json. Try: if(req.session && req.session

Connect WP8 (VM) with node.js server using TCP

余生长醉 提交于 2019-12-12 05:05:29
问题 I'm working on a school project. The goal is to link a Windows Phone 8 (WP8) with a server (node.js using sails.js framework based on express.js) by TCP socket. I have found a great tutorial for the C# part (WP8), I'm working with a Windows 8 Virtual Machine but it's not an issue. (Just slow an borring -_-) Based on the tutorial, I "realized" the WP part. I realized also the node.js server, using socket.io. Here the WP8 tutorial: http://msdn.microsoft.com/en-us/library/windowsphone/develop

Sails.js model saved to session loses custom instance methods?

和自甴很熟 提交于 2019-12-12 04:57:53
问题 On my User model I have a custom instance method, getEarnings() which just adds some other fields in the document together. I'm trying to call this method and display it from my view template as follows, using the user object that's been previously saved to the session after logging in: <div> Your earnings are <%= req.session.user.getEarnings() %> </div> This doesn't work, sails tells me getEarnings doesn't exist on that object. But if I retrieve the user object from the controller (using

Validations for associative models sailsJs

纵然是瞬间 提交于 2019-12-12 04:54:53
问题 I am trying to build a REST API on sailsjs v0.11.0 , I am looking for a way to validate all POST requests. Validation works for simple models. Simple model example: category.js module.exports = { attributes: { name: { type: 'string', required: true, // this works, the POST data is validated, if this field is missing, sails responds with an error json unique: true } } } Associative one to many model example where validation doesnt work: Chapter.js module.exports = { attributes: { name: 'string