Express NodeJS中的HTTP请求

时间:2014-11-14 17:08:04

标签: javascript node.js http express

我有https://github.com/chjj/tty.js/的以下代码:

  this.get("/hola", function(res) {
    iniciar();
  });

  function iniciar() {
    self.init();
  }
  iniciar();

转到localhost:8080/hola,它不会加载。 localhost:8080完美无缺。 self.init()调用一个函数,反过来调用其他函数。问题似乎是以下称为函数:

Server.prototype.initMiddleware = function() {
  var self = this
    , conf = this.conf;

  this.use(function(req, res, next) {
    var setHeader = res.setHeader;
    res.setHeader = function(name) {
      switch (name) {
        case 'Cache-Control':
        case 'Last-Modified':
        case 'ETag':
          return;
      }
      return setHeader.apply(res, arguments);
    };
    next();
  });

  this.use(function(req, res, next) {
    return self._auth(req, res, next);
  });

  this.use(term.middleware());
  this.use(this.app.router);
  this.use(express.static(__dirname + '/../static'));
};

根据express.js文件:

// a middleware sub-stack which prints request info for any type of HTTP request to /user/:id
app.use('/user/:id', function(req, res, next) {
  console.log('Request URL:', req.originalUrl);
  next();
}, function (req, res, next) {
  console.log('Request Type:', req.method);
  next();
});

因此,似乎第一个app.get与其他app.usethis.use之间存在“冲突”。我该如何解决?

1 个答案:

答案 0 :(得分:-1)

这是因为你没有返回任何东西然后浏览器轮询它直到它返回一些东西。

this.app.get("/hola", function(req, res) {
    res.writeHead(200, {'content-type':'text/html'});
    res.end('/*html code here*/');
  });
相关问题