AWS EC2 NodeJS不响应

时间:2018-02-13 17:17:05

标签: node.js amazon-web-services amazon-ec2

我已经启动并运行了AWS EC2 MEAN实例(部分)。该应用程序是一个RESTful JSON服务,据我所知,它正在按预期启动并运行:

var app = require('./app');
var port = process.env.PORT || 3000;
var server = app.listen(port, function() {
console.log('Express server listening on port ' + port);
});

控制台输出:

node server.js

Express server listening on port 3000
Db.prototype.authenticate method will no longer be available in the 
next major release 3.x as MongoDB 3.6 will only allow auth against 
users in the admin db and will no longer allow multiple credentials on 
a socket. Please authenticate using MongoClient.connect with auth 
credentials.

我还为端口3000添加了入站安全组 security group

在浏览器中测试API是我遇到问题的地方......如果我尝试使用http://ec2-XX-XX-XX-XX.com:3000/belts获取对象列表,则调用最终会超时。但是,当我使用http://ec2-XX-XX-XX-XX.com:3000/belts/some_id_here为单个对象尝试GET时,我得到了一个有效的200响应和预期的对象。

当然,一切都按照预期在当地运作。我错过了什么?

提前致谢

//使用格式化的请求代码进行编辑:)

// app.js

var express = require('express'); 
var app = express(); 
var BeltController = require('./controller/BeltController'); 
app.use('/belts', BeltController); 

//皮带控制器

router.get('/', function (req, res) { 
    Belt.find({}, function (err, belts) { 
        if (err) { 
            return res.status(500).send("There was a problem finding the Belt. " + err); 
        } 
        res.status(200).send(belts); 
    }); 
});

0 个答案:

没有答案