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
时间: 2024-09-29 05:44:38

sailsjs learning note的相关文章

Kali linux learning note

from:http://blog.sina.com.cn/s/blog_40983e5e0101dhz0.html 因为kali linux基于debian 7,当然要把这台Acer 4736z原有的debian 7删掉装kali啦,哈哈,这下不必为了BT5装虚拟机了,对于本子里60G的SSD来说还是好事一桩.要把kali当做桌面使用,就必须给kali添加一些软件,修改一些设置才好用,下面记录一下备忘,随时更新. 安装方法,官方文档,硬盘安装Kali Linux 把apt源设为官方提供的国内镜像

shell learning note

shell learning note MAIN="/usr/local/" # 变量大写 STATUS="$MAIN/status" # 美元符加字符串是引用变量值,而美元符加数字表示命令行参数 echo "some words" >>$STATUS/log.log echo "test.sh start at `date '+%m/%d %H:%M:%S'`" >>$STATUS/log.log c

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 the "SQL Server Essentials for Oracle DBAs Jump Start" . DATA BLOCK/EXTEND AND SEGMENT image: http://lh5.ggpht.com/-FxEKn7CCNd0/UetkOxZ6igI/AAAAAAA

[Angular2] @Ngrx/store and @Ngrx/effects learning note

Just sharing the learning experience related to @ngrx/store and @ngrx/effects. In my personal opinion, I fell there are tow different types of coding style by using @ngrx/store only @ngrx/store + @ngrx/effects So How we do with only ngrx/store? Contr

2014/09/30 Learning Note

Vbird Linux: Vim Learning: http://linux.vbird.org/linux_basic/0310vi.php Bash Shell: http://linux.vbird.org/linux_basic/0320bash.php Key words of reminder: /etc/passwd history alias [Tab] Wildcard type ---builtin commands \[Enter] echo $variable

Python 基础 - Day 5 Learning Note - 模块 之 标准库:time (1)

时间的表示方式 1. 间戳 timestamp:  从1970年1月1日 00:00:00 开始按秒计算的偏移量,以float数据类型呈现. 返回时间戳的函数有: time() , clock() 等. 2. sruct_time 元祖方式: 返回struct_time元祖的函数包括 gmtime(), localtime(), strptim(). 返回的元祖包括以下9个元素. 索引 INDEX 属性 ATTRIBUTE 值 VALUES 0 tm_year  比如2011 1 tm_mon

Python 基础 - Day 4 Learning Note - 模块 - Json & Pickle

Json和Pickle的区别 在python的序列化的两个模块中,json模块是用于字符串和python数据类型间进行转换:另一个pickle模块,是用于python特有的类型(所有数据类型和python的数据类型间进行转换.json是可以在不同语言之间交换数据的,而pickle只在python之间使用.json只能序列化最基本的数据类型,json只能把常用的数据类型序列化(列表.字典.列表.字符串.数字.),比如日期格式.类对象!josn就不行了.而pickle可以序列化所有的数据类型,包括类

Python 基础 - Day 4 Learning Note - Generator 生成器

列表生成器/列表解析 list comprehension 简单灵活地创建列表,通常和lambda(), map(), filter() 一起使用 通过列表生成式, 直接创建列表.但是,收到内容限制,列表容量肯定是有限的.而且,创建一个包含100万个元素的列表,不仅占用很大的存储空间,如果我们仅仅需要访问几个元素,那其他的就白占空间.列表生成器能够一边循环一边计算,大大节省大量的空间.是生成器的一种. 只有调用,才能生成. 不支持切片操作,只能通过__next()___一个个取数字. 基本语法

Python 基础 - Day 2 Learning Note - File 文件

文件 - 内建函数Open() FILE操作流程: 打开文件,得到文件句柄并赋值给一个变量 通过句柄对文件进行操作 关闭文件 f.close Open()的基本语法: file_object = open(file_name, access_mode='r', buffering=-1) 手动创建yesterday 文件,access mode = reading, 只读,不可写或追加 f = open('yesterday', 'r', encoding='utf-8',) # r表示read