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 ...
随机推荐
- 跨域 jsonp 和 CORS 资料
http://mp.weixin.qq.com/s/iAShnqvsOyV-Xd0Ft7Nl2Q HTML5安全:CORS(跨域资源共享)简介...ie67不要想了... http://www.cnb ...
- js将接口返回的数据序列化
<div style={{marginLeft: '80px'}}> <pre> {th ...
- ssh 免密登陆
A 要免密码登录要B 那么需要在A电脑上使用命令 ssh-keygen -t rsa 在~/.ssh/ 目录下生成id_rsa.pub 这个文件,然后将这个文件的内容拷到B电脑de ~/.ssh/au ...
- Vim 文件配置
cat ~/.vimrc syntax on set nu set encoding=utf-8 set ts=4 set fileencodings=ucs-bom,utf-8,cp936 set ...
- redis 解析配置文件
在redis安装文件夹里面有redis.conf,查看配置. 一:基础配置介绍 1.units(单位) --这里可以看到 1k和1kb是不一样的, units 这里单位是不区分大小写的,are al ...
- rman备份恢复命令之switch
rman备份恢复命令之switch 一 switch 命令 1 switch命令用途 更新数据文件名为rman下镜像拷贝时指定的数据文件名 更新数据文件名为 set newname 命令指定的名字. ...
- Python 基础关于编码
一.编码的种类: 1 acsic码 基本不用 不同编码之间互用会产生乱码, 2unicode A 字母 4个字节 00000000 00000000 00100100 01000 ...
- SSM整合框架实现ajax校验
SSM整合框架实现ajax校验 刚学习了ssm框架,ajax校验成功,分享下 1.导入jar包
- 效率生产力工具 —— idea 插件
maven helper: 打开该pom文件的Dependency Analyzer视图(在文件打开之后,文件下面会多出这样一个tab), 进入Dependency Analyzer视图之后有三个查看 ...
- Python网络爬虫之图片懒加载技术、selenium和PhantomJS
引入 图片懒加载 selenium phantomJs 谷歌无头浏览器 知识点回顾 验证码处理流程 动态数据加载处理 一.图片懒加载 什么是图片懒加载? 案例分析:抓取站长素材http://sc.ch ...