menu list:

  • custom controller

  • custom 模块使用

  • custom model

  • custom middleware

  • custom service ?

  • 路由与对应的controller处理:

    • 用命令行 & controller 变化

wade-mac:fin_server_invest mac$ sails generate controller mail sendmaillog

info: Created a new controller ("mail") at api/controllers/MailController.js!

  • 路由总汇总:config/routes.js

想往常一样加:, '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!'

});

}

};

  • model command :

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

  • middleware:

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 that use the               *

* `customMiddleware` config option.                                         *

*                                                                           *

****************************************************************************/

middleware: {

/***************************************************************************

*                                                                          *

* The order in which middleware should be 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 will 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 are in `.tmp/public`) *

*                                                                          *

* The HTTP static cache is only active in a 'production' environment,      *

* since that's the only time Express will cache flat-files.                *

*                                                                          *

***************************************************************************/

cache: 31557600000

};

上面的是所有的路由都经过的middleware

疑问:控制某个路由/a  经过middleware: [a, b, c ] , 某个路由/b 经过middleware: [a, c ]

    • service

sailsjs learning note的更多相关文章

  1. Learning note for Binding and validation

    Summary of my learning note for WPF Binding Binding to DataSet. when we want to add new record, we s ...

  2. Learning Note: SQL Server VS Oracle–Database architecture

     http://www.sqlpanda.com/2013/07/learning-note-sql-server-vs.html This is my learning note base on t ...

  3. Course Machine Learning Note

    Machine Learning Note Introduction Introduction What is Machine Learning? Two definitions of Machine ...

  4. shell learning note

      shell learning note MAIN="/usr/local/" # 变量大写 STATUS="$MAIN/status" # 美元符加字符串是 ...

  5. 2014/09/30 Learning Note

    Vbird Linux: Vim Learning: http://linux.vbird.org/linux_basic/0310vi.php Bash Shell: http://linux.vb ...

  6. [Angular2] @Ngrx/store and @Ngrx/effects learning note

    Just sharing the learning experience related to @ngrx/store and @ngrx/effects. In my personal opinio ...

  7. Machine Learning Note Phase 1( Done!)

    Machine Learning 这是第一份机器学习笔记,创建于2019年7月26日,完成于2019年8月2日. 该笔记包括如下部分: 引言(Introduction) 单变量线性回归(Linear ...

  8. Inheritance Learning Note

    好几天没来学习了,昨晚把继承的又整理了一下.想把整理后的东西发到hexo博客上来,却发现命令行又失效了.前几天明明是好的,这几天又没有进行任何操作,网上搜了一下也没有招到合适的解决办法,无奈只能重装了 ...

  9. Machine Learning Note

    [Andrew Ng NIPS2016演讲]<Nuts and Bolts of Applying Deep Learning (Andrew Ng) 中文详解:https://mp.weixi ...

随机推荐

  1. daay04流程控制之for循环

    for循环主要用于循环取值 student=['egon','虎老师','lxxdsb','alexdsb','wupeiqisb'] # i=0 # while i < len(student ...

  2. UVa 11039 - Building designing 贪心,水题 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  3. Module loader:模块加载器

    <p data-height="265" data-theme-id="0" data-slug-hash="XpqRmq" data ...

  4. Win10访问不到XP共享的解决:

    不知道别人的是怎么解决. 反正我这么解决了. 我的win10笔记本,是使用windows帐户登陆的.可以同步很多东西. 同事的电脑是台式老古董XP. 扫描不到网上邻居,手动\\ip也访问不到. 最后安 ...

  5. jdk8-全新时间和日期api

    1.jdk8日期和时间api是线程安全的 1.java.time  处理日期时间 2.java.time.temporal: 时间校正器.获取每个月第一天,周几等等 3.java.time.forma ...

  6. net core2 采坑-- session 缓存

    引用 Microsoft.Extensions.Caching.SqlServer 可以设置存在数据库 Microsoft.Extensions.Caching.Redis 存在redis 参考 ht ...

  7. 如何正确认识Docker Kubernetes 和 Apache Mesos

    参考链接: http://geek.csdn.net/news/detail/229382

  8. Linux 配置selenium + webdriver 环境

    1.ubuntu 自带了python, 可以打开终端输入python 回车后如果显示版本信息就说明已经安装 2.安装安装python setup tools apt-get install pytho ...

  9. if-else和while循环

    用户登陆验证: if-else 判断 #!/usr/bin/env python # -*-coding:utf-8 -*- import getpass passwd=' name='sunhao' ...

  10. react 学习笔记 npm 命令

    第一步: cnpm install --save react react-dom babelify babel-preset-react 第二步: 安装es2015 cnpm install babe ...