cannot access API, got this error in Chrome: ERR_EMPTY_RESPONSE (no data received)

592 views
Skip to first unread message

IVYtony smth

unread,
Apr 20, 2015, 7:58:00 PM4/20/15
to loopb...@googlegroups.com
I couldn't find much information on the internet for this error I got in Chrome by http://localhost:3000/api/categories  

ERR_EMPTY_RESPONSE (no data received)

I thought this might be somethign to do with the middleware settings, but I have the default middleware.js file (see below). Please help

I use the following bootstrap script to create Category objects in my local MongoDB.


var categories = [
{"title" : "Technology Matters", "description": "Blogs on latest technologies"},
{"title" : "Innovative Ideas", "description": "Innovative ideas on the next project"},
{"title" : "Comments on Hot Topics", "description": "My comments on the hot topics"}
];
module.exports = function(server) {
var dataSource = server.dataSources.homeMongoDB;
dataSource.automigrate('Category', function(err) {
if (err) throw err;
var Model = server.models.Category;
//create some sample data
var count = categories.length;
categories.forEach(function(category) {
Model.create(category, function(er, result) {
if (er) return;
console.log('Category created: ', result);
count--;
if (count == 0) {
console.log('Categories all created!');
dataSource.disconnect();
}
});
//could define a model scope here
});
});
};


my middlware.js file:

{
  "initial:before": {
  },
  "initial": {
  },
  "session": {
  },
  "auth": {
  },
  "parse": {
  },
  "routes": {
  },
  "files": {
    "loopback#static": {
      "params": "$!../client"
    }
  },
  "final": {
    "loopback#urlNotFound": {}
  },
  "final:after": {
    "errorhandler": {}
  }
}

and my server.js file:


var loopback = require('loopback');
var boot = require('loopback-boot');
var app = module.exports = loopback();


app.start = function() {
  // start the web server
  return app.listen(function() {
    app.emit('started');
    console.log('Web server listening at: %s', app.get('url'));
  });
};
app.use('/express-status', function(req, res, next) {
  res.json({ running: true });
});
// Bootstrap the application, configure models, datasources and middleware.
// Sub-apps like REST API are mounted via boot scripts.
boot(app, __dirname, function(err) {
  if (err) throw err;
  // start the server if `$ node server.js`
  if (require.main === module)
    app.start();
});


Raymond Feng

unread,
Apr 20, 2015, 8:08:46 PM4/20/15
to IVYtony smth, loopb...@googlegroups.com
You should remove:
 
dataSource.disconnect();

The call above will disconnect your app from the mongodb.

Thanks,

---
Raymond Feng
Co-Founder and Architect @ StrongLoop, Inc.

StrongLoop makes it easy to develop APIs in Node, plus get DevOps capabilities like monitoring, debugging and clustering.

--
You received this message because you are subscribed to the Google Groups "LoopbackJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to loopbackjs+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

IVYtony smth

unread,
Apr 20, 2015, 8:20:48 PM4/20/15
to loopb...@googlegroups.com, ivy...@gmail.com
thanks, but the error persists even after removing dataSource.disconnect();

any other possible reasons?
Reply all
Reply to author
Forward
0 new messages