簡體   English   中英

Node.js身份驗證TypeError:object不是函數

[英]Node.js Authentication TypeError: object is not a function

我目前正在學習如何在Node.js中構建一個簡單的HTTP身份驗證系統的教程 我已經按照教程中的所有步驟進行了操作,但是當我嘗試運行它時,我總是得到這個錯誤: TypeError: object is not a function

這是教程中的代碼:(錯誤發生在第3行)

var http = require("http");
var auth = require("http-auth");
var digest = auth({
  authRealm: "Private area",
  authFile: __dirname + "/htpasswd",
  authType: "digest"
});
var server = http.createServer(function(request, response) {
  digest.apply(request, response, function(username) {
    response.writeHead(200, {"Content-Type": "text/plain"});
    response.write("Hello " + username);
    response.end();
  });
});

server.listen(80);
console.log("Server is listening");

提前致謝! 對不起,如果這個問題非常愚蠢,我是Node.js的新手。 :P

嘗試使用:

var basic = auth.basic({
  authRealm: "Private area",
  authFile: __dirname + "/htpasswd",
  authType: "digest"
});

用於分配basic變量。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM