sails.js

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

不羁岁月 提交于 2019-12-06 02:46:25
问题 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'} }

Sails.js File upload with Skipper to AWS S3

眉间皱痕 提交于 2019-12-06 01:59:22
问题 I have a form where you can upload a file. I upload the file directly with skipper and it works perfectly. req.file('file').upload({ adapter: require('skipper-s3'), key: 'key', secret: 'secret', bucket: 'bucketname' }, function (err, uploadedFiles) { if (err){ // ko } else{ // ok } }); But I want to resize first and then upload the file, so: sharp(original).resize(800).quality(90).toBuffer(function(err, outputBuffer) { if (err) { // ko } // ok outputBuffer; }); So, my question is: How can

Modify response header with sails.js for implementing HSTS

不羁的心 提交于 2019-12-06 00:46:29
问题 I am implementing a nodejs application using sails.js. I want my user to communicate only through https. So for doing that I need to configure my server my way so that with each response it will add a header "Strict-Transport-Security", "max-age=31536000" to tell browser to communicate with HSTS only. Now how I can modify every response header that I am going to send from sails js.I searched the documentation but did not found any help. 回答1: Policies are only applied to the controllers that

Hosting sails.js application from subdirectory

江枫思渺然 提交于 2019-12-06 00:35:10
Due to certain restrictions, I need to host my application from a subdirectory (e.g. hostname.domain.com/mysailsapp). The webserver is nginx and set to proxy connections to sails/node. The issue I'm facing is that grunt automatically builds in the links to include frontend javascript/css/images/etc, but the entire sails app is expecting to be at the root level. Everything works fine when I connect directly to sails via port 1337 as sails is at the root, but when connecting though the subdirectory URL proxied to sails this will not work. I didn't see an easy way to configure sails to change

choosing assets sailsjs

橙三吉。 提交于 2019-12-06 00:21:53
I've started using SailsJS for a small web app and so far it's great. However I'm struggling with the assets and layout. Basically I would like to be able to use different type of assets (groups of css files) depending on the page. For this, I wrote 2 different layouts, each should includes the correct css files. However, when I add those files in the config/assets.js files there all bundled together. Is there a way to specifiy in my layout which assets i want to use ? I know you can specify assets.js or assets.styles but I would like to be able to create my own group . I also tried to put

How to use React.js to render server-side template on Sails.js?

99封情书 提交于 2019-12-05 23:29:23
问题 I am trying to build an isomorphing app with Sails.js and React. Client-side part is easy. But I run into problems with server-side rendering. When I try to server-render an *.jsx file with React, I got this: renderToString(): You must pass a valid ReactElement I am using sailsjs, react and sails-hook-babel (for ES6 syntax). ./assets/components/Auth.jsx: import React from 'react'; export class Auth extends React.Component { constructor(props) { super(props); } render() { return ( <div

Adding missing request parameter before persistance in Sails.JS

空扰寡人 提交于 2019-12-05 22:54:31
Is it possible to "insert" a missing parameter (in case it was not sent), in order to persist them all via req.params.all() ? Currently trying to do so, gets me a no method 'setParameter' error. It's not possible to add anything into the result of req.params.all() in Sails without implementing custom middleware, since it's parsed at request time and provided to route handlers before any user-level code runs. However, if what you're looking for is default parameter options, in Sails v0.10.x you can use the req.options hash for this. If you wanted to set a default limit for a blueprint "find",

SailsJS Policy based route with a view

[亡魂溺海] 提交于 2019-12-05 22:47:08
问题 I'm trying to use the routes.js to define a route to '/account' . I want whoever is trying to access that path to go through the UserController and the checkLogin action and if the security check passes, then the user should be rendered with the defined view which is home/account Here is my code: routes.js: '/account': { controller: 'UserController', action: 'checkLogin', view: 'home/account' } policies.js: UserController: { '*': 'isAuthenticated', 'login': true, 'checkLogin': true } It let's

sails.js 0.10.0-rc4 cannot flash message to ejs view

拟墨画扇 提交于 2019-12-05 22:15:47
In server js if (!user) { if (isEmail) { req.flash('error', 'Error.Passport.Email.NotFound'); sails.log.warn('User Email not fond.'); } else { req.flash('error', 'Error.Passport.Username.NotFound'); sails.log.warn('User name not found.'); } ejs view <form role="form" action="/auth/local" method="post"> <input type="text" name="identifier" placeholder="Username or Email"> <input type="password" name="password" placeholder="Password"> <button type="submit">Sign in</button> </form> <% if (typeof message!== 'undefined') { %> <%= message %> <% } else { %> You E-mail and passport is correct! <% } %>

Is it possible to use the Mocha Framework against a model in Sails.js?

倾然丶 夕夏残阳落幕 提交于 2019-12-05 22:02:18
问题 Sails.js uses the MVC pattern for Node.js and I was wondering if Mocha could be hooked up for testing Models. 回答1: I know you asked this awhile ago, but I was searching around myself and there's not much out there at the moment. I figured I'd drop what I found into this answer... I found some discussion on the sails github and a gist with some example code. There is also a second discussion with more examples. 回答2: Check out wolfpack. It's a SailsJS model-testing library that allows you to