我对要解决的问题有疑问,但似乎一直在发生。我有一个简单的服务器端点/example
,我从curl 123.45.678.901/example
调用了该端点,服务器运行了一个函数并向我返回内容,然后我res.end()
,但是我注意到尽管我没有调用该端点,但再次单击该端点,并且可以在打开服务器的终端上看到控制台之一。出现日志。这是代码
const express = require ("express");
const app = express();
const port = 80;
//middleware function
const authenticateUser = (req,res,next) => {
console.log("header w/ access_token sent in:", req.header("token"))
request.get({
url: [url here were I authenticate the token they sent me]
}, function optionalCallback(err, httpResponse, body){
if (err) {
res.send("Authentication failed, please check your access_token");
res.end();
}
console.log("Authentication has been cleared");
next()
})
}
//here I tell express to use my middleware always
app.use(authenticateUser);
app.get("/example", (req,res) =>{
console.log("in /example endpoint");
(some function being called here that returns something to the client)
res.end();
})
app.listen(port, () => console.log(`App is listening on port ${port}`));
这是对服务器进行幻像调用时看到的,我知道我没有调用端点,因为如果我有undefined
,我会看到那里显示了一个令牌,该令牌是通过Headers传入的cURL: