sailsjs learning note
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的更多相关文章
- 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 ...
- 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 ...
- Course Machine Learning Note
Machine Learning Note Introduction Introduction What is Machine Learning? Two definitions of Machine ...
- shell learning note
shell learning note MAIN="/usr/local/" # 变量大写 STATUS="$MAIN/status" # 美元符加字符串是 ...
- 2014/09/30 Learning Note
Vbird Linux: Vim Learning: http://linux.vbird.org/linux_basic/0310vi.php Bash Shell: http://linux.vb ...
- [Angular2] @Ngrx/store and @Ngrx/effects learning note
Just sharing the learning experience related to @ngrx/store and @ngrx/effects. In my personal opinio ...
- Machine Learning Note Phase 1( Done!)
Machine Learning 这是第一份机器学习笔记,创建于2019年7月26日,完成于2019年8月2日. 该笔记包括如下部分: 引言(Introduction) 单变量线性回归(Linear ...
- Inheritance Learning Note
好几天没来学习了,昨晚把继承的又整理了一下.想把整理后的东西发到hexo博客上来,却发现命令行又失效了.前几天明明是好的,这几天又没有进行任何操作,网上搜了一下也没有招到合适的解决办法,无奈只能重装了 ...
- Machine Learning Note
[Andrew Ng NIPS2016演讲]<Nuts and Bolts of Applying Deep Learning (Andrew Ng) 中文详解:https://mp.weixi ...
随机推荐
- what’s this?
jdk,jre,jvm三者区别:JDK: (Java Development ToolKit) java开发工具包.JDK是整个java的核心! 包括了java运行环境 JRE(Java Runtim ...
- selenium(七)expected_conditions EC
判断一个元素是否存在,如何判断alert弹窗出来了,如何判断动态的元素等等一系列的判断,在selenium的expected_conditions模块收集了一系列的场景判断方法, 一.功能介绍和翻译 ...
- tf.nn.conv2d
tf.nn.conv2d(input, filter, strides, padding, use_cudnn_on_gpu=None, name=None) input: 指需要做卷积的输入图像,它 ...
- tp配置
<?php// +----------------------------------------------------------------------// | ThinkPHP [ WE ...
- DevExpress Windows 10 UWP Controls新版亮点
行业领先的.NET界面控件2018年第二次重大更新——DevExpress v18.2日前正式发布,本站将以连载的形式为大家介绍新版本新功能.本文将介绍了DevExpress Windows 10 U ...
- 干货分享!DevExpress v17.1最新版帮助文档下载大全
DevExpress v17.1.5帮助文档下载列表大全来啦!包含.NET.VCL.HTML/JS系列所有帮助文档,提供CHM和PDF两个版本.除已停止更新的Silverlight.Windows 8 ...
- 从原理上理解如何由震源机制一个节面的解:strike,dip,rake可以求出另一个节面的解
首先,需要回到最原始的地震矩的表达式: 已知strike,dip,rake 根据strike和dip可以求出v,根据strike,dip,rake,可以求出u. 把求出来的v和u互换,相当于原来的位错 ...
- SharePoint REST API - 文件夹和文件
博客地址:http://blog.csdn.net/FoxDave 本篇讲述如何通过REST操作文件夹和文件. 使用REST操作文件夹 在你知道某个文档库中的文件夹的URL时,可以使用如下的代码获 ...
- Linux 虚拟内存机制
每个进程都有自己独立的4G内存空间,各个进程的内存空间具有类似的结构. Linux内存管理采用的是页式管理,使用的是多级页表,动态地址转换机构与主存.辅存共同实现虚拟内存 一个新进程建立的时候,将会建 ...
- Linux文件系统命令 touch/rm
命令:touch 功能:创建文件,后接相对路径或者绝对路径 eg: touch ./ren/jin/gui.txt 命令:rm 功能:删除文件,当删除的是目录的时候要加-R参数进行递归删除. eg: ...