开发者

Routes with parameters gets called twice?

I am creating a NodeJS web application via ExpressJS. I have the following two routes (among others):

app.get('/user/reset/verify', function(req, res) {
    console.log("Executing verification index.");
    res.render("verify/index");
});

app.get('/user/reset/verify/:email/:token', function(req, res) {
    console.log("Executing verification change.");
    res.render("verify/change");
});

When I go to the verification index page, I see "Executing verification index." printed once on the console. However, when I go to the verification change page, I see "Executing verification change." printed twice on the console.

I have noticed that this is a trend with the routes in my app. Routes that contain parameters are always executed twice, while routes without parameters are only (properly) executed once.

Why are the routes with parameters being executed twice?

The views that are being rendered only contain simple HTML - nothing that would cause an开发者_如何学Pythonother request to the page. Also, I am issuing these requests from a Chrome browser.

Platform/Versions:

  • NodeJS: 0.5.5 windows build (running on Win 7)
  • Express: 2.4.6
  • Connect: 1.7.1


The second request is the /favicon.ico Try to console log your request.url in your http_server request handler, you'll see the first is the browser url and the next the favicon.


If you are using chrome: When you write your url chrome send a get request to check the url before you hit enter.

Try to log the middleware url console.log(req.url) position your console aside your broswer then start to write the url, you will see console logging a get access.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜