Sailsjs for backend rest api

==
help with salsas:

  • Google Groups: sails.js
  • IRC: #sailsjs
  • Stack Overflow (using tag sails.js)

==
instal

mac:
nodejs.org
download pkg
(
/usr/local/bin/node
/usr/local/bin/npm
add to $PATH
/usr/local/bin
)

(sudo) npm install sails –global

==
setup first project
sails new firstApp

move to folder
cd firstApp

to start sails:
sails lift

generate new model via blueprint engine
sails generate api user

then question about migrate on sails lift
choose alter in non Prod env
change firstApp/config/model.js

module.exports.models = {
migrate: 'alter'
};

http://localhost:1337/user
first results
in json response []

localhost:1337/user/create?name=HJSnips
results in

[
 
  {
    "name": "HJSnips",
    "createdAt": "2016-03-30T07:30:39.555Z",
    "updatedAt": "2016-03-30T07:30:39.555Z",
    "id": 1
  }
]

==
use Sails built-in integration
with websockets and Socket.io

create
firstApp/assets/js/test.js

io.socket.get('/user', function (users){ console.log(users);});
io.socket.on('user', function (message) {
console.log("Got message: ", message);
});

==
policies
firstApp/config/policies.js
module.exports.policies = {
'UserController': {
'create': ['sessionAuth']
}
};

==
static assets
npm install sails-generate-static --save

sails generate static

sails lift
now when adding content to assets Grunt will create routes files in .tmp

== css assets
to use css in html via grunt make sure:

<!--STYLES-->
<!--STYLES END-->

are in!

<head>
<title>New Sails App</title>
<!-- Viewport mobile tag for sensible mobile support -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
   
<!--STYLES-->
<!--STYLES END-->
</head>

<html>
<body>
<!--STYLES-->
<!--STYLES END-->
</head>
<body>
<!--TEMPLATES-->
<!--TEMPLATES END-->
<!--SCRIPTS-->
<!--SCRIPTS END-->
</body>


</html>