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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Course Machine Learning Note

    Machine Learning Note Introduction Introduction What is Machine Learning? Two definitions of Machine ...

  4. shell learning note

      shell learning note MAIN="/usr/local/" # 变量大写 STATUS="$MAIN/status" # 美元符加字符串是 ...

  5. 2014/09/30 Learning Note

    Vbird Linux: Vim Learning: http://linux.vbird.org/linux_basic/0310vi.php Bash Shell: http://linux.vb ...

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

    Just sharing the learning experience related to @ngrx/store and @ngrx/effects. In my personal opinio ...

  7. Machine Learning Note Phase 1( Done!)

    Machine Learning 这是第一份机器学习笔记,创建于2019年7月26日,完成于2019年8月2日. 该笔记包括如下部分: 引言(Introduction) 单变量线性回归(Linear ...

  8. Inheritance Learning Note

    好几天没来学习了,昨晚把继承的又整理了一下.想把整理后的东西发到hexo博客上来,却发现命令行又失效了.前几天明明是好的,这几天又没有进行任何操作,网上搜了一下也没有招到合适的解决办法,无奈只能重装了 ...

  9. Machine Learning Note

    [Andrew Ng NIPS2016演讲]<Nuts and Bolts of Applying Deep Learning (Andrew Ng) 中文详解:https://mp.weixi ...

随机推荐

  1. 随机生成id

    function getRandom(){ return Math.random().toString(36).substring(7);}

  2. Introduction to Cryto & Crptocurrencies Lecture 1

    Lecture 1.2 Hash Pointer & Data Structure Use Case 1. 什么是Block Chain呢? 想象一个像链表一样的结构,只不过与通常的指向下一块 ...

  3. inode占用100%时硬盘无法写入文件故障处理

    故障现象: 分区无法写入文件. 故障分析: 执行df -h命令发现空间占用不到50%,执行df -hi,发现某分区IUse%值为99%,说明innode已经用完,应该是某些目录下存在大量的小文件导致. ...

  4. nginx在linux上的安装与配置详解(一)

    Nginx的安装与配置详解 (1)nginx简介     nginx概念: Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like ...

  5. Find the Missing Number II

    Giving a string with number from 1-n in random order, but miss 1 number.Find that number. Notice n & ...

  6. Xilinx 7 series FPGA multiboot技术的使用(转)

    reference:https://www.cnblogs.com/chensimin1990/p/9067629.html 当升级程序有错误的时候,系统会启动golden bitstream 注意: ...

  7. Java流对象理解

    马士兵老师,曾在Java的学习过程中,将Java的流比作管道,认为很贴切,在此笔者也建议读者在学习过程中作类似比喻,形象化的学习 Java根据数据流向的不同分为输入流和输出流: Java根据处理数据类 ...

  8. 51nod1009

    给定一个十进制正整数N,写下从1开始,到N的所有正数,计算出其中出现所有1的个数.   例如:n = 12,包含了5个1.1,10,12共包含3个1,11包含2个1,总共5个1. Input 输入N( ...

  9. jmeter中操作数据库

    jmeter是如何操作数据库的? 步骤一:导入jdbc的jar包,jmeter本身不能直接连接mysql,所以需要导入第三方的jar包来连接mysql 点击测试计划,添加classpath,选择mys ...

  10. SparkStreaming实时日志分析--实时热搜词

    Overview 整个项目的整体架构如下: 关于SparkStreaming的部分: Flume传数据到SparkStreaming:为了简单使用的是push-based的方式.这种方式可能会丢失数据 ...