2

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

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

有谁知道是否可以在expressjs中做到这一点。

提前致谢

布鲁诺

4

1 回答 1

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(默认绑定是 0.0.0.0)中扔一个 htpasswd 对,你就可以参加比赛了。

于 2015-03-25T18:22:51.977 回答