P
P
pavlyk2015-12-27 22:01:55
Node.js
pavlyk, 2015-12-27 22:01:55

Why is the page not changing again on nodejs?

I can’t understand one moment, I wrote the processing of url parameters if it’s empty, display index.html if not, then error.html

function onRequest (request, response) {
  var parse = urlutils.parse(request.url, true);
  view(parse.pathname, parse.query.text, function (render) {
    response.writeHead(200, {"Content-Type": "text/html"});
    response.write(render);
    response.end();
    // console.log('write ' + parse.pathname);
  });
}

Everything works out and everything seems to be fine, but I noticed such a feature, because. when I go to the site, the first ulr 127.0.0.1/ is sent to me, and the second is 127.0.0.1/favicon.ico , when the favicon arrives, the function is triggered that I need to show error.html and in the console using the console.log command I have to display two lines in a row
/
/favicon.ico
But the correct page is displayed first, there are no errors .... I can’t understand why. in the code I don’t check this favicon and, according to the idea, there should be an error then.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pavlyk, 2015-12-27
@pavlyk

function view(page, text, callback) {
  if (page === '/') {
    action = 'render';
    page = 'index';
  } else if (page === '/ajax') {
    translate(text, function (result) {
      callback(result);
    });
    return;
  } else {
    action = 'render';
    page = 'error';
  }
  if (action = 'render') {
    callback(fs.readFileSync('front/' + page + '.html'));
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question