繁体   English   中英

尝试使用npm start启动node.js应用,但在浏览器中得到err_empty_response

[英]Trying to start a node.js app using npm start but get err_empty_response in browser

我从内部存储库中克隆了一个node.js应用程序,该应用程序对其他开发人员而言效果很好,但对我而言却不是。 这是我被要求进行的第一个节点应用程序,但不知道如何调试它。 在收到许多其他错误之后,我终于修复了所有问题(克隆和依赖关系部分),当我执行npm start时,我可以看到该应用程序已启动,并且光标在命令提示符下闪烁,但是当我尝试执行以下操作时:浏览器到该路径( http:// localhost:8000 / service )-除了一条消息,我没有在浏览器中返回任何响应:

This page isn’t working
localhost didn’t send any data.
ERR_EMPTY_RESPONSE

我在控制台中看不到任何错误。 我尝试使用Postman,并收到以下消息:

Could not get any response
There was an error connecting to localhost:8000/service/.

我的package.js中的代码如下:

"dependencies": {
"ansc-core": "^1.8.2",
"lodash": "~4.17.0",
"request": "~2.87.0",
"abcdef": "^1.6.1",
"underscore": "^1.9.1"
 },

我的ansc.json(设置了端口号)中的代码是:

"port":8000,
"server_ssl_key_store": "sss/xxx/yyyy/zzz.43",
"server_ssl_key_store_password": "",
"cpu_count": 1
}

service.js中的代码是:

const $ = require('abcdefg').xxxxxx;

class Service {
constructor() {
    console.log("in service constructor");
    $.info({ service: 'up' });
}


  findAll() {
    return new Promise((resolve) => {

        resolve([]);

    });
  }
}

module.exports = Service;

route.js中调用service的代码是:

const Service = require('./service');
const $ = require('abcdefg').xxxxxx;

const service = new Service();

const Routes = {

getEntity(req, res) {
    service.findAll().then((items) => {
        console.log("inside getentity");
        res.send(items);
    }).catch((error) => {
        $.error(error);
        res.status(500).send(error);
    });
    }
 };

 module.exports = Routes;

最后,index.js(这是应用程序的入口点)为:

  const ansc = require('ansc-core');
  const routes = require('./src/service/routes');

 ansc.routes((app) => {
  console.log("before app get");
  app.get('/service', routes.getEntity);
 }).start();

module.exports = ansc;

还有其他人遇到这个或类似的问题吗?

我这是愚蠢的错误-通过将http更改为https可以解决!

暂无
暂无

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

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