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

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);

    });

    });


sails.js mvc framework learning的更多相关文章

  1. 全端开发必备!10个最好的 Node.js MVC 框架

      Node.js 是最流行的 JavaScript 服务端平台,它允许建立可扩展的 Web 应用程序.Node.js 包含不同类型的框架,如 MVC 框架.全栈框架.REST API  以及大量的服 ...

  2. Sails.js中文文档

    Sails.js中文文档   http://sailsdoc.swift.ren/ Sails.js是一个Web框架,可以于轻松构建自定义,企业级Node.js Apps.它在设计上类似于像Ruby ...

  3. 十款最佳Node.js MVC框架

    十款最佳Node.js MVC框架摘要:Node.js是JavaScript中最为流行的框架之一,易于创建可扩展的Web应用.本文分享十款最佳的JavaScript框架. Node.js是JavaSc ...

  4. 私人定制,十款最佳Node.js MVC框架

    Node.js是JavaScript中最为流行的框架之一,易于创建可扩展的Web应用.本文分享十款最佳的JavaScript框架. Node.js是JavaScript中最为流行的框架之一,易于创建可 ...

  5. 【转】Code Your Own PHP MVC Framework in 1 Hour

      原文: https://www.codeproject.com/Articles/1080626/Code-Your-Own-PHP-MVC-Framework-in-Hour --------- ...

  6. Sails.js中文文档,Sails中文文档

    Sails.js中文文档   http://sailsdoc.swift.ren/ Sails.js是一个Web框架,可以于轻松构建自定义,企业级Node.js Apps.它在设计上类似于像Ruby ...

  7. Mithril – 构建杰出 Web 应用的 JS MVC 框架

    Mithril 是一个客户端的 Javascript MVC 框架.它是一个工具,使应用程序代码分为数据层,UI 层和粘合层.提供了一个模板引擎与一个虚拟的 DOM diff 实现,用于高性能渲染,支 ...

  8. Atitit. js mvc 总结(2)----angular 跟 Knockout o99 最佳实践

    Atitit. js mvc 总结(2)----angular  跟 Knockout o99 最佳实践 1. 框架 angular 跟Knockout 1 2. 2. 简单的列表绑定:Knockou ...

  9. 理解ASP.NET MVC Framework Action Filters

    原文:http://www.cnblogs.com/darkdawn/archive/2009/03/13/1410477.html 本指南主要解释action filters,action filt ...

随机推荐

  1. JavaScript(数据类型、字符串操作)

    JS基础 建议:一般情况下不在 head 标签中写 js 语句,因为该 js 语句会在 body 加载之前就执行,可能导致某些效果无效 // 单行注释 /*多行 * 注释*/ // 控制台输出语句 c ...

  2. 【HAOI 2012】高速公路

    Problem Description \(Y901\) 高速公路是一条重要的交通纽带,政府部门建设初期的投入以及使用期间的养护费用都不低,因此政府在这条高速公路上设立了许多收费站. \(Y901\) ...

  3. LINQ之路14:LINQ Operators之排序和分组(Ordering and Grouping)

    本篇继续LINQ Operators的介绍,这里要讨论的是LINQ中的排序和分组功能.LINQ的排序操作符有:OrderBy, OrderByDescending, ThenBy, 和ThenByDe ...

  4. _skill,_skill_category

    _skill,_skill_category -- 自定义商业技能-- 小技巧:配合增加自定义商业技能._add skill [ID _skill `skillId`商业技能ID `skillIcon ...

  5. redis-server 使用

    redis.conf ################################## NETWORK ##################################### bind 127 ...

  6. 简单粗暴的上传项目至 Github

    嗯,写了一个项目,觉得还OK,就想放在 Github 继续维护和方便使用,那么如何简单快速的将代码上传至 Github 上? 1.  你得有自己的 Github账号,如何创建账号这里就不说了.因为.. ...

  7. itsdangerous

    将字典进行加密.解密 通过私钥保证安全性 serializer=TimedJSONWebSignatureSerializer(私钥,过期时间) dumps(字典)=====>返回加密字符串 l ...

  8. less点滴

    1.简单的嵌套: less中显示: css中显示 2.作为值的变量: less中: @green: #801f77;@baise:white; header,footer{ background: @ ...

  9. Spring Boot配置加载顺序

    如果加载的配置有重复的,它们的加载顺序是这样的,数字越小的优先级越高,即优先级高的覆盖优先级低的配置. Devtools global settings properties on your home ...

  10. opencv3.0配置opencv_contrib

    在opencv3.0中无法直接使用sift,surf等特征点检测算子,需要额外配置opencv_contrib. 在查看网上诸多教程,失败n次后,终于找到了正确的配置方式. visual studio ...