将自定义中间件安装到hubot的express中

时间:2015-04-16 20:54:59

标签: express hubot

有没有办法将自己的自定义中间件安装到hubot提供的快速对象中?

我想使用这样的代码,但我从未看到“添加中间件”或“初始化快速”消息。我使用的代码here作为模型。

我可以以某种方式覆盖setupExpress吗?或者,有没有办法让Robot子类化呢?

    # Setup our own express handler                                                                                                                                                        
    express = require 'express'
    robot.express = app = express()
    app.use require 'body-parser'

    app.use (req, res, next) ->
            robot.logger.info "Added middleware"
            req.rawData = ''
            req.on 'data', (chunk) ->
                    req.rawData += chunk

            req.on 'end', () ->
                    next()


    robot.logger.info "Setting up new express module"

    robot.emit 'express-loaded', @
    @loaded = true

    @init = (port, bindAddress) =>
            robot.logger.info "Initializing express"
            unless @initialized
                    try
                            @server = app.listen( port || process.env.PORT || 8080, bindAddress || process.env.BIND_ADDRESS || '0.0.0.0' )
                            @router = app
                            @initialized = true
                    catch err
                            robot.logger.error "Error trying to load"
                            process.exit 1
            @

0 个答案:

没有答案