简体   繁体   English

http.createServer 从不调用回调 | 节点.js

[英]http.createServer never calling callback | Node.js

I'm working on a Node.js project and am attempting to use the http module.我正在处理一个 Node.js 项目并尝试使用http模块。

Currently I have the following code:目前我有以下代码:

http.createServer(function(req, res){
    console.log("here!!!!"); 
});

This never outputs to the console.这永远不会输出到控制台。 To test further, I placed a breakpoint on console.log("here!!!!");为了进一步测试,我在console.log("here!!!!");上放置了一个断点console.log("here!!!!"); . . The breakpoint was never hit.断点从未被击中。 I then set a breakpoint on http.createServer(function(req, res){ . The program did stop at this breakpoint. Stepping over showed that it then does not go into the callback but instead skips over it completely.然后我在http.createServer(function(req, res){上设置了一个断点。程序确实在这个断点处停止。单步执行表明它然后没有进入回调而是完全跳过它。

Any idea what would cause this?知道什么会导致这种情况吗?


Details:细节:

app.js应用程序.js

var express = require('express'); 
var app = express(); 

app.set('view engine', 'jade');
app.use(express.static(__dirname + '/public')

app.get('/map', function(req, res){
    res.render('view', {type: "block", name: req.query.name, latitude: req.query.latitude, longitude: req.query.longitude, zoom: req.query.zoom}); 
}); 

//Occurs when the picture is requested
app.get(/^\/omb\/1.0.0\/(.+)\/(.+)\/(.+)\/(.+)\.[a-zA-Z]*$/, function(req, res){
    var MosaicStreamer = require('./models/MosaicStreamer.js'); 
    var ms = new MosaicStreamer; 
    var configs = {library: req.params[0], zoom: req.params[1], column: req.params[2], row: req.params[3]}; 
    ms.handleTile(configs); 
});

app.listen(3000, function(){
    console.log('Tile Server listening on port 3000...'); 
});

Let me copy & paste code from NodeJS documentation - you miss .listen() call.让我从.listen()文档中复制和粘贴代码 - 你错过了.listen()调用。

'use strict';

const http = require('http');

const server = http.createServer((req, res) => {
  console.log(req)
  res.end();
});

server.listen(8000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM