sails.js

Why is `req.user` undefined for socket requests in Sails.js, Angular.js and Passport.js?

故事扮演 提交于 2019-12-30 10:48:45
问题 I am trying to get the questions for the current user with a request like this: http://localhost:1337/question/forme As part of the GET request, I am able to access req.user.username and serve the JSONresponse when accessing it from the browser. When I try to make the same Socket.get() request from my Angular client.js file, it doesn't work. I also tried to access it using browser console and it fails for socket.get() requests. 回答1: I spent a large time figuring out all the moving parts to

One to many associations using existing join table

风格不统一 提交于 2019-12-30 06:54:12
问题 I'm converting the backend of an existing application that uses MariaDB to use Sails (v0.10.0-rc7) and I'm stuck trying to figure out how to get all permissions for a role populated into the Role model given the underlying schema structure I have to work with. There are three tables that are used to currently get a role and it's associated permissions, and the working query looks something like this: SELECT pm.permission, pm.permkey FROM role_master rm INNER JOIN role_perm rp ON ( rm.roleid =

SailsJS - How to specify string attribute length without getting error when creating record?

♀尐吖头ヾ 提交于 2019-12-30 06:52:07
问题 I'm using Sails 0.9.8 paired with MySQL and wanting to do something like this localhost:1337/player/view/<username of player> instead of localhost:1337/player/view/<id of player> So I put something like this in the model: 'username' : { type: 'string', unique: true, minLength: 4, maxLength: 32, required: true }, But I've got an error whenever I run sails lift: { [Error: ER_TOO_LONG_KEY: Specified key was too long; max key length is 767 bytes] code: 'ER_TOO_LONG_KEY', index: 0 } So after I run

SailsJS - How to specify string attribute length without getting error when creating record?

浪尽此生 提交于 2019-12-30 06:51:25
问题 I'm using Sails 0.9.8 paired with MySQL and wanting to do something like this localhost:1337/player/view/<username of player> instead of localhost:1337/player/view/<id of player> So I put something like this in the model: 'username' : { type: 'string', unique: true, minLength: 4, maxLength: 32, required: true }, But I've got an error whenever I run sails lift: { [Error: ER_TOO_LONG_KEY: Specified key was too long; max key length is 767 bytes] code: 'ER_TOO_LONG_KEY', index: 0 } So after I run

How do I handle a Unique Field in sails?

爱⌒轻易说出口 提交于 2019-12-30 01:35:10
问题 I've defined a unique field in my model but when I tried to test it seems like it's not being checked by sails because I get a Error (E_UNKNOWN) :: Encountered an unexpected error: MongoError: E11000 duplicate key error index: instead a sails ValidationError. What is the best way to handle a unique field in sails? // model/User.js module.exports{ attributes: { email: {required: true, unique: true, type: 'email' }, .... } // in my controller User.create({email: 'hello@gmail.com'}).then(...)

What is the proper way to integrate dynamic content into the layout.ejs file in a Sails.JS application?

ぐ巨炮叔叔 提交于 2019-12-29 08:33:30
问题 Say I wrote a blog app in Sails.js. On every page in this app, there is a sidebar widget called "Recent Posts", where it lists the titles of the 5 most recent posts and clicking on them takes you to the post in question. Because this sidebar widget is present on every page , it should be in layout.ejs . But, here we have a conflict - dynamic content is only supposed to be pulled from the database in the controller action for rendering a specific view. This dynamic content isn't for a specific

Get livereload to work with Sails.js

别等时光非礼了梦想. 提交于 2019-12-29 06:25:17
问题 I am new to both Sails and grunt so I might be missing the obvious. I am trying to automatically refresh my sails app in the browser whenever files change . I start the app with sails lift and it runs on the default port 1337 . I tried adding options: {livereload:true} to my grunt-contrib-watch configuration but as far as I understand I need to somehow inject the livereload JavaScript into my page? I tried to use grunt-contrib-connect with the livereload option to inject the JavaScript but it

MongoError: topology was destroyed sailsjs

佐手、 提交于 2019-12-28 15:58:19
问题 When I try to create this error shows up: Error (E_UNKNOWN) :: Encountered an unexpected error MongoError: topology was destroyed at Server.insert (/Users/oscargallon/Documents/developer/sails/reyesmagoswebpae/node_modules/sails-mongo/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:797:49) here's my model module.exports = { attributes: { name: { type: 'string', required: true }, email: { type: 'String', required: true }, description: { type: 'string', required: true },

sails.js access controller method from controller method

爱⌒轻易说出口 提交于 2019-12-28 03:54:08
问题 How come in sails you cannot access other controller methods from within another one? like this. module.exports = findStore: -> # do somthing index: -> @findStore(); # Error: undefined Compiled module.exports = { findStore: function() {}, index: function() { return this.findStore(); // Error: undefined } }; If you can't do this, then why not? how else should I be doing this... 回答1: Having the same problem for last few hours. I used the api/services folder. It may not be exactly what you need

Sails socket authorization (using passport)

笑着哭i 提交于 2019-12-25 16:51:24
问题 I am using passport for authentication/authorization along with local strategy and a JWT. Following some research (intensive googling ;) I understand that the best place for the authorization is to use a policy as it applies both for a regular HTTP requests and a socket request (through SailsSocket object that can send 'virtual' HTTP-like requests). I am now trying to figure out how to use sockets properly and I've seen that there's a beforeConnect handler that allows to reject a connection.