[英]Hubot/Express: disable basic auth in a specific route
我正在使用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中做到這一點。
提前致謝
布魯諾
將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初始化腳本中將htpasswd對折騰成BIND_ADDRESS=localhost
(默認綁定為0.0.0.0),您將開始比賽。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.