sails.js

Sails.js with skipper: check if file input were empty before starting upload

旧时模样 提交于 2019-12-11 02:48:35
问题 I'm using Sails 11.1 and skipper 0.5.5. I have a form to create an article in my app. An image can be attached to an article, so there is an input file. I would like to check, server-side, if this input file was empty, before trying to start upload. Is it possible, and if yes, how can I do this? I tried to check req.files , or req.files.photo ("photo" is the input name) and req.body.photo , but they are always undefined, even if there is a file. req.file('photo') is always defined, so I can't

How can I set a meta description tag in Sailsjs using ejs templates?

好久不见. 提交于 2019-12-11 02:44:06
问题 I would like to be able to set the description meta tag from the sails controller action. I have searched all over, but the only example involves the page title. This is my first node.js and sailsjs site, am I going about this the wrong way? Something like this: module.exports = { index: function (){ res.view( { title: 'The Title Text', metaDescription: "The Description Text" }); } }; 回答1: Yes, this is correct. You can insert in your template with <!DOCTYPE html> <html> <head> <title><%=

How to create a new instance of a model in sailjs?

亡梦爱人 提交于 2019-12-11 02:24:01
问题 I want to create a not persisted new instance from a model, populate some attributes and send it back as a JSON response from a controller action. In rails it's pretty simple to get a new instance of a model with Model.new , but how can I do that with waterline or sails.js ? If you are familiar with rails: Model.new -> Creates a new instance of a model. How can I do this in Sails.JS? Model.create -> Creates a new instance of a model, which is (already) persisted. I've already checked the

Sails.js associations

半世苍凉 提交于 2019-12-11 02:14:53
问题 I am beginning with sails.js and I am completely lost with my sql queries. I have the following tables : genres +-----------+--------------+------+-----+ | Field | Type | Null | Key | +-----------+--------------+------+-----+ | id | int(6) | NO | PRI | | name | varchar(100) | NO | | | slug | varchar(255) | NO | | | type | varchar(32) | NO | | | parent_id | int(11) | YES | MUL | +-----------+--------------+------+-----+ genres_radios +----------+--------+------+-----+ | Field | Type | Null |

Using express middleware in Sails.js to serve static files

不问归期 提交于 2019-12-11 01:59:40
问题 I have trouble using the express middleware on sails 0.11.0. I tried the following in http.js file. module.exports.http = { customMiddleware: function (app) { console.log("middleware"); app.use('/test', express.static('****/****/*****/testProject/api/controllers' + '/public/')); } }; But it doesn't work, I am missing something. 回答1: With the latest Sails (0.12), calling express-style app.use(...) isn't directly possible from config/http.js (or as a policy) because the custom middleware

SailsJS Linker (Grunt) Ignore files (Gruntfile.js)

爷,独闯天下 提交于 2019-12-11 01:58:02
问题 I am using bower for asset management. The Bootstrap bower repo is coming with a Gruntfile.js. Is there a way to exclude this from the linker? I have tried: var jsFilesToInject = [ '!**Gruntfile.js', // ... ] But it's not working - am I putting this string in the wrong spot? Generated HTML and Error File Structure P.S. I followed this guide to get here: StackOverFlow Question and ran bower install bootstrap and bower install angular . 回答1: This is a bug in the current sails frontend generator

Sails nested model collection

爱⌒轻易说出口 提交于 2019-12-11 01:09:20
问题 i have 3 models. User model: module.exports = schema: true attributes: login: type: 'string' required: true hosts: collection: 'host' via: 'owners' accounts: collection: 'account' via: 'users' Host model: module.exports = attributes: url: type: 'string' required: true unique: true owners: collection: 'user' via: 'hosts' accounts: collection: 'account' via: 'host' Account model: module.exports = attributes: provider: type: 'string' required: true password: type: 'string' users: collection:

Sails.js REST without action

一世执手 提交于 2019-12-10 23:39:19
问题 I'm trying to create a REST API in Sails.js 0.9x I have a controller like the following: UsersController = { list: function(req, res){ var users [{username: "max"}, {username:'alison'}]; res.send(users); }, single: function(req, res){ var user = {username: 'max'}; res.send(user); } }; How would I be able to access the URLs using an HTTP Method and the Route without specifying the action name? For example HTTP GET to mysite.com/users/ will invoke the list action HTTP GET to mysite.com/users/1

How to fetch the image files from a server and zip it in sailsjs

旧城冷巷雨未停 提交于 2019-12-10 22:38:44
问题 I want to zip all the images from s3 urls. I am doing it on server side on sailsjs framework. I tried using axios to download the images and used 'zipdir'. The images are getting downloaded in temp folder. But its not getting zipped properly. this.downloadFiles = function (req, res) { var resObj = {} async.waterfall([ this.createFolder.bind(undefined, req), this.downloadFilesAxios.bind(undefined, req), this.zipTheFiles.bind(undefined, req) ], function final(err, result) { if (err) { console

Sails JS with EJS but linker to compile handlebars public templates

纵饮孤独 提交于 2019-12-10 21:39:43
问题 I'm a bit new to Node and javascript backend frameworks so please bear with me: I've been searching around to find a nice combination of front-end, back-end (MVC)frameworks to work with Node, and I've currently decided upon using SailsJS/EmberJS to make a boilerplate which I can play around with and maybe use for future projects. SailsJs (out of the box generated app) uses EJS to compile back-end views. EmberJs (by default, starter kit) uses handlebars to compile front-end views. I want to