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

最新文章

  1. maven核心,pom.xml详解(转)
  2. BZOJ 3143 HNOI2013 游走 高斯消元 期望
  3. 使用Unity制作游戏关卡的教程(一)
  4. Windows 下Python操作MySQL
  5. sql server 2008有关SQL的模糊查询
  6. leetCode 26.Remove Duplicates from Sorted Array(删除数组反复点) 解题思路和方法
  7. jquery和highcharts折线图、柱形图、饼状图-模拟后台传參源代码
  8. Python 输出文件内容到网络端口
  9. c/c++/java如何访问数据库(优秀博文)
  10. vue 中 直接操作 cookie 及 如何使用工具 js-cookie
  11. Socket网络编程--简单Web服务器(1)
  12. express 写一个简单的web app
  13. [ 原创 ] Java基础6--构造函数和抽象类的性质
  14. GPU性能:光栅化、图层混合、离屏渲染
  15. JZOJ.5246【NOIP2017模拟8.8】Trip
  16. Intent详解以及实例
  17. struct 方法使用
  18. 开源知识库管理系统选型 centos6.4 搭建knowlededgeroot-1.0.4知识库平台
  19. Select2下拉选项库 部分积累
  20. ViewData、ViewBag和TempData比较

热门文章

  1. 有多个.h引用时,不能有using namespace std
  2. servlet之中文乱码:request.getParameter()
  3. Yii2.0 数据库查询 [ 2.0 版本 ]
  4. JavaScrip(三)JavaScrip变量高级操作(字符串,数组,日期)
  5. Linux Hadoop集群搭建第二步:--------SSH免密登陆
  6. js如何生成一个对象,并转化为json字符串
  7. Vue基础以及指令
  8. 深入理解java虚拟机---Class文件(二十)
  9. 利用include动作实现参数传递
  10. 安装ubuntu不能引导win7