Menu list:
Custom Controller
Custom module Use
Custom model
Custom Middleware
Custom Service?
Wade-mac:fin_server_invest mac$ sails generate controller mail Sendmaillog
Info:created a new controller ("Mail") at api/controllers/mailcontroller.js!
As usual add:, ' Get/make/a/mail ': "Mailcontroller.sendmaillog"
/**
* Mailcontroller
*
* @description:: server-side logic for managing mails
* @help:: See Http://links.sailsjs.org/docs/controllers
*/
Module.exports = {
/**
* ' Mailcontroller.sendmaillog () '
*/
Sendmaillog:function (req, res) {
var log4js = require (' Log4js ');
var logger = Log4js.getlogger ();
Logger.debug ("Some debug Messages");
Return Res.json ({
TODO: ' Sendmaillog () is not implemented yet! '
});
}
};
Https://www.digitalocean.com/community/tutorials/how-to-create-an-node-js-app-using-sails-js-on-an-ubuntu-vps
$sails Generate model User name:string email:string password:string
$sails Generate Controller User index show edit delete
https://gist.github.com/mikermcneil/6255295
Look at Config/http.js
Module.exports.http = {
/****************************************************************************
* *
* Express middleware to use for every Sails request. To add custom *
* Middleware to the mix, add a function to the middleware Config object and *
* Add its key to the "order" array. The $custom key is reserved for *
* Backwards-compatibility with Sails v0.9.x apps the *
* ' custommiddleware ' config option. *
* *
****************************************************************************/
Middleware: {
/***************************************************************************
* *
* The order in which middleware should is run for HTTP request. (The Sails *
* Router is invoked by the "router" middleware below.) *
* *
***************************************************************************/
Order: [
' Startrequesttimer ',
' Cookieparser ',
' Session ',
' Myrequestlogger ',
' Bodyparser ',
' Handlebodyparsererror ',
' Compress ',
' Methodoverride ',
' Poweredby ',
' $custom ',
' Router ',
' www ',
' Favicon ',
' 404 ',
' 500 '
],
/****************************************************************************
* *
* Example custom middleware; Logs each request to the console. *
* *
****************************************************************************/
Myrequestlogger:function (req, res, next) {
Console.log ("Requested::", Req.method, Req.url);
return next ();
},
/***************************************************************************
* *
* The body parser that would handle incoming multipart HTTP requests. by *
* Default as of v0.10, Sails uses *
* [Skipper] (http://github.com/balderdashy/skipper). See *
* Http://www.senchalabs.org/connect/multipart.html for other options. *
* *
***************************************************************************/
Bodyparser:require (' skipper ')
},
/***************************************************************************
* *
* The number of seconds to cache flat files on disk being served by *
* Express static middleware (by default, these files is in '. Tmp/public ') *
* *
* The HTTP static cache is only active in a ' production ' environment, *
* Since that's the only time Express would cache flat-files. *
* *
***************************************************************************/
cache:31557600000
};
Above is the middleware of all routes.
Question: Control a route/A through middleware: [A, B, c], a route/b through middleware: [A, C]
SAILSJS Learning Note