sails.js

Give parameter with json format in sails

空扰寡人 提交于 2019-12-10 21:26:18
问题 In my controllers and other areas where there's a req object, I can access request parameters using req.params('username') . This is fine for normally POSTed data, but I want my API to accept a JSON object in the request body and convert it to parameters that I can still access with req.params() . So for example, if I send this as the POST request body to my controller action: {'username': 'Chris', 'password': 'mypass'} I want to be able to get the username and password using req.params(

sails beforeValidation not called

青春壹個敷衍的年華 提交于 2019-12-10 21:03:32
问题 I saw that the beforeValidation is called for both create and update so I'm thinking of using this callback to manipulate the posted data before saving to the database but it seems like beforeValidation is not being called because _csrf is being save in the database and the name is not slugified. Example: var slugify = require('slug'); ..... beforeValidation: function(values, next){ // don't save _csrf token in database if(values._csrf) delete values._csrf; // slugify the name before saving

Subdomain Routing in Sails.js

故事扮演 提交于 2019-12-10 20:56:48
问题 I am trying to figure out a way to route subdomains in Sails.js in such a way, that is completely dynamic, the default routing does not seem to allow this. For example; if a user goes to theirname.example.com, the route would read that as example.com/users/theirname, and any parameters on the subdomain would tag onto the end /user/theirname. I have been searching the web for quite a few hours for some solid information on how to achieve such a thing. Any help is much appreciated. 来源: https:/

sails-mongo adapter, normalize error messages

时间秒杀一切 提交于 2019-12-10 20:49:24
问题 I am trying out sailsJs with mongodb using the sails-mongo adapter. After adding validations to a model, I get the following response when the validation fails. Users.js Model: module.exports = { schema: true, attributes: { name: { type: "string", unique: true }, email: { type: "email", unique: true }, password: { type: "string", required: true } } } Validation error while using sails-mongo adapter: { "error": { "error": "E_UNKNOWN", "status": 500, "summary": "Encountered an unexpected error"

Sails is not injecting the files within the assets folder

左心房为你撑大大i 提交于 2019-12-10 20:05:35
问题 I just did a fresh installation of sails (v0.11.0) in my server and after checking this up and working on controllers I found that css, js and templates files included into the assets folders are not being injected to the layout, if there any reason for this to happen? I mean, it is a clean fresh sails installation.... 回答1: In my quest to get SailsJS to auto-inject stylesheets into the layout file under views/layouts/layout.handlebars in my case, I've found out a couple things... When you

Can we change the value of attribute on after/before Create() callback in sails?

China☆狼群 提交于 2019-12-10 19:57:41
问题 I have a scenario where I have to populate attribute of model with its id. For eg.. In User model: module.exports = { attributes: { activation_link: "string" }, afterCreate: function(value, cb) { value.activation_link = "localhost:1337/user/action/"+ value.id; cb(); } The activation_link's modified value has to saved in the database too. How can that be achieved? 回答1: According to this and this your code should actually work: your manipulations in afterCreate are supposed to mutate the

How do I perform this query using sailsjs ORM (waterline)

穿精又带淫゛_ 提交于 2019-12-10 19:57:05
问题 How do I perform this query? SELECT * FROM blog GROUP BY MONTH(createdAt) What I've tried: Blog.find() .groupBy({MONTH:'createdAt'}) .exec(function(err,months){ res.view({ layout: 'blogLayout', archive:months }); }); Gives me Error: Cannot groupBy without a calculation 回答1: Waterline (the ORM used by sails) at this point only supports using groupBy in combination with sum(), count() etc. You can find the line of code that verifies this here: https://github.com/balderdashy/sails-mongo/blob

Sails.js create Index(root) Controller

放肆的年华 提交于 2019-12-10 19:53:24
问题 I was wondering if there is a way to have an index controller with an index action. my root is a login page and I wanted to detect if the users session is already authenticated and if so redirect them to another page. Is there specific notation for how the controller is named? I have already tried IndexController.js and MainController.js. I can't seem to find anything in the documentation about this. Sails.js Ver: 0.11.0 回答1: You need to make the controller and action yourself. From there,

Sails.js Single Page Application (SPA) — redirect all missing/unused routes to a single controller action

你离开我真会死。 提交于 2019-12-10 19:36:08
问题 I'm developing a single page application (SPA) using Sails.js as a backend. All I want is to redirect all routes to a single controller action. However, when I do the following: // config/routes.js module.exports.routes = { 'GET *': 'MainController.application' }; All requests are getting redirected to my application route, even for static files like CSS/JavaScript, etc. Is there an easy way to fallback to my application route when there is no other means to handle it? I want: All static

Step by Step guide to using a migrating tool for production SailsJS system

余生长醉 提交于 2019-12-10 18:53:52
问题 I very new to production sailsjs environment, I need a way to add table changes which I make in my sailsjs Models in Dev to be applied to Sailsjs Production Models. Does anyone dealt with this before ? Can someone guide me through it please ? It would be really helpful to have a step by step guide, All i need is to have the Model attributes created in the Production database tables. 回答1: Well you can always jump in here: https://gitter.im/balderdashy/sails and you might find some help. 来源: