• 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
  • 相关阅读:
    WEB功能测试说明
    年轻的采访可以学到很多东西
    金融系列11《电子现金应用》
    vs2010调用matlab2011下的.m文件
    使用VS2010调用matlab的mat格式文件
    matlab mex入门简介
    MEX文件编写和调试
    MAT文件操作
    8.Redis 数据备份与恢复
    JAVA_OPTS设置
  • 原文地址:https://www.cnblogs.com/no7dw/p/4300721.html
Copyright © 2020-2023  润新知