sails.js

SailsJS - using sails.io.js with JWT

99封情书 提交于 2019-12-04 11:27:13
问题 I have implemented an AngularJS app, communicating with Sails backend through websockets, using sails.io.js. Since the backend is basically a pure API and will be connected to from other apps as well, I'm trying to disable sessions completely and use JWT. I have set up express-jwt and can use regular HTTP requests quite nicely, but when I send a request through sails.io.js, nothing happens at all - websocket request keeps pending on the client, and there's nothing happening on the server

Unable to get session for socket in sailsjs after restart

蹲街弑〆低调 提交于 2019-12-04 11:09:12
问题 I trying to build socket driven application on sailsjs, it is small and I need only memory session adapter, but when I restart application, I getting after socket.get('/') : Could not parse: No session data returned, and an error was encountered saving session data for the first time: undefined SyntaxError {stack: (...), message: "Unexpected token N"} sails.io.js:142 Uncaught Error: Server response could not be parsed! No session data returned, and an error was encountered saving session data

sails.js nested models

淺唱寂寞╮ 提交于 2019-12-04 10:19:39
In sails.js 0.10 I'm trying to do the following // user.js module.exports = { attributes: { uuid: { type: 'string', primaryKey: true, required: true } , profile: { firstname: 'string', lastname: 'string', birthdate: 'date', required: true } } }; I'm getting an error when trying to create a user and sailsJS doesn't recognize the "profile" attribute. I'm not sure if sails supports the nested JSON structure, and if it does I'm not sure how to structure it. error: Sent 500 ("Server Error") response error: Error: Unknown rule: firstname I've tried the following but it failed too // user.js module

How to use an error-handler callback in a Sails.js policy?

爱⌒轻易说出口 提交于 2019-12-04 10:07:37
After asking this question , I've found that I can add a callback array to an endpoint in a sails app like this: file: /api/policies/somepolicy.js module.exports = thisIsAnArrayOfCallbacks; This works ok while each member of thisIsAnArrayOfCallbacks is a function which accepts req , res , and next as arguments. The controller call executes all the functions in the array and the expected result is obtained in a normal flow. But when using an errorHandler callback (like the one in this example ) which takes an additional err parameter, it doesn't work as expected: the express-only version app

Sails.js: How to know if the request contains a file to upload?

血红的双手。 提交于 2019-12-04 09:13:49
I have the next action in one of my controllers, its function is upload a image file or create a new cover model using a video url, its work fine but when the request has a header Content-Type: multipart/form-data and does not contains a file the action throw a timeout error in req.file() . upload: function(req, res) { res.setTimeout(0); function onCreateCover(err, cover) { if (err) { return res.negotiate(err); } else { res.status(201); return res.json(cover); } } if (/^multipart\/form-data/.test(req.headers['content-type'])) { req.file('image').upload({ maxBytes: 2000000, dirname: coverDir },

Minify all of sails.js served html

丶灬走出姿态 提交于 2019-12-04 08:37:28
问题 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. 回答1: 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

How to use external rest api in Sails js (nodejs MVC)

让人想犯罪 __ 提交于 2019-12-04 07:45:01
Im using sailsjs as a MVC for node js, i'm still learning it. I managed to get data from my own database and use it. But now i need/want to get data from an external rest api. I used this in my controller: // api/controllers/SomeController.js test : function(res,req){ var j; var https = require('https'); var options = { hostname: 'testing.atlassian.net', port: 443, path: '/rest/api/2/search?jql=project=ABC', method: 'GET', headers: {'Authorization': 'Basic ' + 'SuperSecretLoginAndPassword'} }; var req = https.request(options, function(res) { res.setEncoding('utf8'); res.on('data', function(d)

How to gzip JavaScript and CSS assets in Sails.js?

落花浮王杯 提交于 2019-12-04 07:39:03
I am trying to enable gzip compression for my assets in a Sails.js (Node) application. When launching the app in production environment, all the assets in assets/linker/js and assets/linker/styles are concatenated, minified, uglified successfully (as specified in the Gruntfile). The following output files are generated: .tmp/ public/ min/ production.js production.css I would like to add gzip compression as well, therefore i have installed grunt-contrib-compress and added the compress task to the Gruntfile. I can get the following results with successfully gzipped files. .tmp/ public/ min/

Between Dates using Waterline ORM SailsJS

人盡茶涼 提交于 2019-12-04 07:07:50
Goal: Return a list of items that were created between two dates. According to this issue https://github.com/balderdashy/waterline/issues/110 there is no between function just yet. However the work around is the following: User.find({ date: { '>': new Date('2/4/2014'), '<': new Date('2/7/2014') } }).exec(/* ... */); To be more exact, we don't want the hard coded dates above so we read in the input from a form submission like so: start = new Date(req.param('yearStart') + '/' + req.param('monthStart') + '/' + req.param('dayStart')); end = new Date(req.param('yearEnd') + '/' + req.param('monthEnd

Keep Object In Memory Between Requests with SailsJS/ Express

流过昼夜 提交于 2019-12-04 06:17:01
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() function takes way too long and I would rather keep the synapticNetwork object in memory while the server