目的:加快开发速度,总结使用方法:

menu list:

  • custom controller
  • custom 模块使用
  • custom model
  • custom middleware
  • custom
  • service

关于启动 ##:


config/connection -- db connection

入口: app.js

config/bootstrap - 启动入口app.js 后的

config/policies 配置

bin/*.json

关于DIY ##:


config/router

路由与对应的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 本项目单独的业务逻辑
  • lib 存放一些共用的lib
  • data 存放常用配置、数据

CRUD

  • CRUD -- model

  • CRUD -- 尽量使用 native

    • 速度快
    • 适合复杂操作
  • CRUD -- 坑

    • 并发:使用findandmodify & update(upsert) & findorcreate

    //findandmodify

    Order.native(function (err, collection) {

    collection.findAndModify(query, null, {$set: update_data}, {'new': false}, function (err, newResult, detail) {

    //update upsert

    User_account_cashflow.native(function(err, colletion){

    colletion.update(query, {$set: cashflow },{upsert:true, multi:false} , function(err, effectNum, result){

    callback(err, cashflow, result.updatedExisting);

    });

    });


最新文章

  1. 自定义分页控件PageList
  2. python学习之路-day6-面向对象
  3. h5专题应该兼容那些浏览器?
  4. pylint window下安装与使用
  5. Javascript计数器
  6. dom添加事件
  7. nginx 注册为服务
  8. 使用SQLCOMMAND以及SQLADAPERT 调用存储过程
  9. MemCached Cache Java Client封装优化历程
  10. zepto的scrollTo,实现锚点跳转
  11. 监控apache虚拟主机进程
  12. Java实践 — SSH远程执行Shell脚本(转)
  13. 学大伟业 国庆Day2
  14. CentOS系统下安装python3+Django
  15. Vue+Element-ui+DateTimePicker 日期时间选择器传值给后台
  16. Java框架spring Boot学习笔记(七):@Configuration,@bean注解
  17. oracle的Date类型遇到MyBatis产生的坑
  18. python内置模块之unittest测试(五)
  19. 转载:Linux操作系统(1.3.1)《深入理解Nginx》(陶辉)
  20. OC分割输入验证码的视觉效果

热门文章

  1. HDU 5279 YJC plays Minecraft(NTT+分治)
  2. ActiveReports 大数据分析报告:2018中国电影再次迎来黄金时代
  3. python版 mapreduce 矩阵相乘
  4. java IO和NIO区别
  5. windows平台下安装linux
  6. 第一个Python窗体程序
  7. Unity---判断某个点是否在摄像机的视景范围内
  8. Spring boot连接MongoDB集群
  9. CSS样式表与HTML结合的方法
  10. 使用 udev 高效、动态地管理 Linux 设备文件