sails.js

sailsjs use mongodb without ORM

巧了我就是萌 提交于 2019-12-04 06:03:06
问题 I want to use mongodb with sails but without any ORM. So below is my service to connect mongodb. Service: //DbService.js const MongoClient = require('mongodb').MongoClient; module.exports = { db:function(req, res){ var connect=MongoClient.connect("mongodb:***********").then(function (err, database) { if(err) console.log(err); else{ database=database.db('*****'); return connect; } }); } } After connection i have called it in controller, But getting TypeError: Cannot read property 'then' of

Modify response header with sails.js for implementing HSTS

狂风中的少年 提交于 2019-12-04 05:43:44
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. Policies are only applied to the controllers that you explicitly assign them to in config/policies.js . Instead of using a policy, try adding an express

Sails.js File upload with Skipper to AWS S3

跟風遠走 提交于 2019-12-04 05:43:31
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 upload the outputBuffer instead of req.file('file') ? Instead of using skipper-s3 you can use the aws-sdk

Sails js using models outside web server

家住魔仙堡 提交于 2019-12-04 05:26:27
I want to create a cli to create admin users I have the user model setup in api/models/User.js and in cli on var User, program; program = require("commander"); User = require("../api/models/User"); program.version("0.0.1"); program.command("create_user").description("Create a user into database").action(function() { return console.log(User); }); program.parse(process.argv); User log is: User = { attributes: { username: "string", password: "string", } }; and no waterline methods available to use. You can use sails run <command> . Simply create <appPath>/commands/index.js with this content:

Sails.js v 10.2 missing express app

对着背影说爱祢 提交于 2019-12-04 05:23:47
How can we access express app instance from Sails global object after upgrade? When in sails.0.9x we can access express app instance by sails.express.app after upgrading to 0.10, the express function is missing How can we call the app? Our test case failed since using supertest, how can we fixed the sails.express.app problem var request = require("supertest"); describe("TestController", function() { describe(".plain", function () { it("returns 200 with status done", function(done) { request(sails.express.app) .get("/test/plain") .expect(200, { status: "done" }) .expect("Content-Type", /json/)

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

 ̄綄美尐妖づ 提交于 2019-12-04 05:03:21
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 className='auth'> Very simple element without any logic just for test server-rendering. </div> ); } } ./api

what is 'info: transport end (undefined)'? in Sails.js

徘徊边缘 提交于 2019-12-04 04:52:46
问题 When I start the server 'sails lift', it shown debug: -------------------------------------------------------- debug: :: Mon May 05 2014 10:59:17 GMT+0700 (ICT) debug: debug: Environment : development debug: Port : 1337 debug: -------------------------------------------------------- info: handshake authorized AUcEOqQtYzXw0jBMiSbp info: handshake authorized t9Y7k4zozlyXd1nwiSbq info: transport end (socket end) info: transport end (undefined) I wonder what are those last two lines? info:

How to use multiple layout within a SailsJS app?

隐身守侯 提交于 2019-12-04 04:30:19
My Sails.js application have separate frontend and admin layout. My view engine is ejs . How do I use separate layouts for frontend and admin site? Can I use specific layout for each action? From Sails.js Documentation : At least in EJS, instead of indicating your custom layout with the layout local, you must use _layoutFile: res.view({ _layoutFile: 'relativePathToYourCustomLayoutFromTheTargetView.ejs' }); The path to the layout you're wanting to use should be specified relative to the view you're rendering. So if you're in the create action of the UserController, rendering a view (views/user

How to make a phonegap mobile app from SailsJS

对着背影说爱祢 提交于 2019-12-04 04:11:53
问题 I've been learning to use NodeJS and SailsJS just this day and now I have a created a basic web app with user signup and list system. It is basically almost exactly the same as this: http://activityoverlord.herokuapp.com/ Now, since I have read from the official SailsJS documentation that it could be also be on phonegap using "sails build" that will output a "www" folder. -> https://github.com/coderaven/sails-docs/blob/master/What-Is-Sails.md Now, all I'm seeing are the javascript in the

Sails can not connect to mySql

狂风中的少年 提交于 2019-12-04 04:03:35
问题 On a brand new sails projet, I've added: localMysql: { adapter: 'sails-mysql', host: 'localhost', user: 'homestead', password: 'secret', database: 'sails' }, on config.connections.js, and: connection: 'localMysql', migrate: 'alter' on config.models.js. A user model is set on api/models/User.js: // api/models/User.js module.exports = { attributes: { appid: { type: 'string' }, uid: { type: 'string' }, hid: { type: 'string' }, params: { type: 'string' } } } When running, sails lift, I obtain: