Sails.js + Passport.js authentication through websockets

Alternatively, you can hijack the ‘router:request’ event to plug in passport for socket requests. I do this in ‘config/bootstrap.js’: module.exports.bootstrap = function (cb) { var passport = require(‘passport’), initialize = passport.initialize(), session = passport.session(), http = require(‘http’), methods = [‘login’, ‘logIn’, ‘logout’, ‘logOut’, ‘isAuthenticated’, ‘isUnauthenticated’]; sails.removeAllListeners(‘router:request’); sails.on(‘router:request’, function(req, res) { initialize(req, res, function () { … Read more

Upload multiple files in angular

Here is file value binding directive example .. http://plnkr.co/edit/B13t84j5IPzINMh1F862?p=preview Js code is: var app = angular.module(‘myApp’, []); app.controller(‘MainCtrl’, function($scope) { $scope.name=”World”; $scope.files = []; $scope.upload=function(){ alert($scope.files.length+” files selected … Write your Upload Code”); }; }); app.directive(‘ngFileModel’, [‘$parse’, function ($parse) { return { restrict: ‘A’, link: function (scope, element, attrs) { var model = $parse(attrs.ngFileModel); var … Read more

What services would one add to the api/services folder in sails.js

a service would be in my opinion, a piece of logic that you need in multiple locations of your app. for example an email service. the following is taken directly from the sails-wiki github page. // EmailService.js – in api/services exports.sendInviteEmail = function(options) { var opts = {“type”:”messages”,”call”:”send”,”message”: { “subject”: “YourIn!”, “from_email”: “info@balderdash.co”, “from_name”: “AmazingStartupApp”, … Read more

How do I connect bower components with sails.js?

In Sails 0.10 the ‘assets/linker’ directory no longer exists, however I found a lead on simple solution that gives some automation to the bower -> asset linker workflow while also allowing some granular control over what exactly ends up getting linked. The solution is adding grunt-bower to your Sails.js compileAssets task grunt.registerTask(‘compileAssets’, [ ‘clean:dev’, ‘bower:dev’, … Read more

npm install not installing latest version on GitHub

By default, NPM dependencies are pulled from the NPM repository. Authors must manually upload new versions of their software to the NPM repository, so the “@latest” version of the code hosted on NPM is different from the latest version of the code that exists anywhere (e.g., on GitHub). According to the NPM repository’s info page … Read more

Create config variables in sails.js?

You can create your own config file in config/ folder. For example config/myconf.js with your config variables: module.exports.myconf = { name: ‘projectName’, author: ‘authorName’, anyobject: { bar: “foo” } }; and then access these variables from any view via global sails variable. In a view: <!– views/foo/bar.ejs –> <%= sails.config.myconf.name %> <%= sails.config.myconf.author %> In … Read more