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. 【原创】QString 函数 replace()indexOf()、 lastindexOf()

    1.替换函数 示例: QString x = "Say yes!"; QString y = "no"; x.replace(, , y); // x == & ...

  2. Grafana配置SingleStat图表信息(三)

    Grafana是一个用于展示数据的工具,配置数据源,直接连接数据库.(这里的数据库应该是结果库,直接需要给用户看的结果数据信息) SingleStat : 想用来展示单一数据信息的图表,效果图如图 ( ...

  3. 【转载】《Learn More Study Less》整体性学习方法

    原文 忘记在哪里看到这本书的介绍了,据说是一个小子自学1年,完成了4年麻省理工的课程,然后写了一本他学习方法的书.我搜了一下,居然中英文版都有,就花时间好好读了一遍,就是这本. 以下是这本书的完整笔记 ...

  4. vue-router-4-编程式导航

    想要导航到不同的 URL,用 router.push 方法,会向 history 栈添加一个新的记录 <router-link> <==>router.push // 字符串 ...

  5. 使用RxSwift 实现登录页面的条件绑定

    我们在使用MVC建构进行开发时,对登录页面用户名密码等进行的处理一般是这样的,点击登录按钮判断用户框以及密码框输入的合法性,用一堆if真是屎一般!或者用textfield的代理来进行响应其实也是屎一般 ...

  6. :单件模式:Singleton

    #ifndef __SINGLETON_H__ #define __SINGLETON_H__ class Singleton { private: static Singleton* instanc ...

  7. java8新特性Lambda练习

    练习内容: 1.实现案例 /** *使用lambda表达式定义Collections.sort() */ /** *使用lambda表达式自定义比对方式 */ @Test public void Te ...

  8. python中的argparse模块(参数解析)

    import argparseparse = argparse.ArgumentParser()parse.add_argument("a", help="params ...

  9. SQL-1 选取表中某一属性最大值的所有信息 查找最晚入职员工的所有信息

    题目描述 查找最晚入职员工的所有信息CREATE TABLE `employees` (`emp_no` int(11) NOT NULL,`birth_date` date NOT NULL,`fi ...

  10. vue-router + ElementUI实现NavMenu 导航菜单 选中状态的切换

    elemen-ui官方网站:http://element.eleme.io/#/zh-CN/component/menu 新手小白利用vue+element-ui尝试搭建后台管理系统, 效果是这样的, ...