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 ...
随机推荐
- [AtCoder2558]Many Moves
Problem 共有n个格子,有两个硬币在a,b格子上,还有q个操作. 每个操作给你一个编号,要求将一个硬币移到这个编号上. 问你硬币移动的总距离最小值. Solution O(n^3):DP[i][ ...
- Grafana展示報表數據的配置(二)
一.Grafana以圖表的形式展示KPI報表的結果數據1.按照日期顯示數據達標量與未達標量2.顯示當前報表的最大值.最小值.平均值.總量3.報表結果數據的鏈接分享與頁面嵌入,用戶無需登錄直接訪問報表統 ...
- js 判断某个元素是否隐藏或显示
//判断某个元素是否显示 true:是 false:不是 var isVisible = $('#myDiv').is(':visible'); //判断某个元素是否隐藏 true:是 false:不 ...
- 从头入手jenkins
前段时间项目处在测试阶段.5个测试妹子围着转,你不知道幸福的啊. 项目一共有开发.测试.生产三个环境,每次打包要切换分支代码,然后使用Xcode打包,然后生成ipa,再上传到蒲公英或者fir给测试妹子 ...
- 八. Python基础(8)--函数
八. Python基础(8)--函数 1 ● 函数返回布尔值 注意, 自定义的函数也可以是用来作逻辑判断的, 例如内置的startswith()等函数. def check_len(x): ' ...
- python第一个程序HelloWorld
在写第一个python程序之前,我们还需要了解的一个东西就是python解释器 解释器,顾名思义,就是解释一段代码的机器,程序运行的平台,例如Java的解释器就是jdk. 我们在写好的python代码 ...
- git 命令篇
*利用命令在仓库新建文件 *远程克隆到本地 *查看子文件 *创建新的分支 合并分支 删除分支 *合并分支 冲突 当Git无法自动合并分支时,就必须首先解决冲突.解决冲突后,再提交,合并完成. 用g ...
- oracle sequence
代码块 方法一: (1)删除序列; (2)重新创建: 这个方法比较简单粗暴. drop sequence sequence_name; create sequence sequence_name mi ...
- TensorFlow函数:tf.ones_like
tf.ones_like 函数 ones_like( tensor, dtype=None, name=None, optimize=True ) 定义在:tensorflow/python/ops/ ...
- day 54 jQuery 的初步基础
jQuery介绍 jQuery是一个轻量级的.兼容多浏览器的JavaScript库. jQuery使用户能够更方便地处理HTML Document.Events.实现动画效果.方便地进行Ajax交互, ...