javascript - Node.js Express and Parse.com -
i've set node.js server-app want parse.com requests. want return parse-object json-representation.
my route:
var blog = require('./models/model'); app.get('/api/article/:permalink', function(req, res) { res.json(blog.getarticle(req.params.permalink)); });
and model:
var parse = require('parse/node').parse, // load parse node package keys = require('../../config/keys'); // keys config-file hosted services parse.initialize(keys.app, keys.js); module.exports = { getarticle: function(permalink) { "use strict"; var article = parse.object.extend('article'); var query = new parse.query(article); query.include('category'); query.include('profile'); query.equalto('permalink', permalink); query.find().then(function(results) { return results; }, function(error) { return error; }); } };
the thing is, returns nothing when call article permalink know exist (example: http://localhost/api/article/testfoo). don't errors either.
my browser console flashes message split second reads:
resource interpreted document transferred mime type application/json: "http://localhost/api/article/testfoo"
any suggestions doing wrong?
you trying use return value of async function. can't work, need pass callback (or res
object) getarticle
function, use send data back.
with callback:
app.get('/api/article/:permalink', function(req, res) { blog.getarticle(req.params.permalink, function(data) {res.json(data)}); });
...
getarticle: function(permalink,callback) {
...
query.find().then(function(results) { callback(results); }, function(error) { callback({error: error}); });
Comments
Post a Comment