Hubot / Express:禁用特定路径中的基本身份验证

时间:2014-06-24 16:50:36

标签: node.js express basic-authentication hubot

我正在使用Hubot,我已经定义了环境变量EXPRESS_USER和EXPRESS_PASSWORD来启用基本身份验证。 Hubot使用快递,基本上是

setupExpress: ->
    user    = process.env.EXPRESS_USER
    pass    = process.env.EXPRESS_PASSWORD
    stat    = process.env.EXPRESS_STATIC

    express = require 'express'

    app = express()

    app.use (req, res, next) =>
      res.setHeader "X-Powered-By", "hubot/#{@name}"
      next()

    app.use express.basicAuth user, pass if user and pass
    app.use express.query()
    app.use express.bodyParser()
    app.use express.static stat if stat`

我想在不需要基本身份验证的脚本中公开HTTP命令。但是,我无法更改Hubot中的代码,表示正在初始化

robot.router.get '/some-anonymous-path', (req, res) ->
  console.log 'Should be here without need to authenticate

有没有人知道是否可以在快递中做到这一点。

提前致谢

布鲁诺

1 个答案:

答案 0 :(得分:0)

如何将nginx放在你的Hubot面前?然后,您还可以添加SSL,仅允许访问特定路径,重写URL或甚至提供由hubot脚本创建的静态内容。一个简单的例子nginx.conf块:

upstream hubot {
  server localhost:8080;
}
server {
  listen 80;
  satisfy any;
  allow 127.0.0.1;
  deny all;
  location ~ ^/(public|obscured) {
    allow all;
    proxy_pass http://hubot;
  }
  location ~ ^/(static) {
    auth_basic "Restricted";
    auth_basic_user_file htpasswd;
    root /www;
  }
  location ~ {
    auth_basic "Restricted";
    auth_basic_user_file htpasswd;
    proxy_pass http://hubot;
  }
}

然后在/ etc / nginx / htpasswd和你的hubot init脚本集BIND_ADDRESS=localhost中抛出一个htpasswd对(默认绑定为0.0.0.0),你将会参加比赛。

相关问题