I have this code that produces the desired effect in a desktop browser.
var express = require('express'),
http = require('http'),
app = express(),
mongo = require('mongodb'),
ObjectId = require('mongodb').ObjectID,
ISODate = require('mongodb').ISODate,
monk = require('monk'),
db = monk('localhost:27017/database', {
username : 'user',
password : 'pwd'
}),
server = http.createServer(app);
app.configure(function(){
app.use(cors());
app.use(express.json());
});
app.get('/get-audio/:name', function(req, res){
var hash = req.params.name,
dbData = db.get('audio_database');
dbData.findOne({'hash':hash}, function(e, data){
if(e){res.send(400, e);}
else{
res.send(200, data);
}
});
});
server.listen(8080);
console.log('Listening on port 8080.');
In a desktop browser I get a JSON object and all is good. In mobile browsers the data object is always null. There is no error thrown. There is nothing thrown. I know this isn't a full-on REST server, but that isn't what I need. I am taking the data object and using a few attributes from the object to do some other things and not actually outputting raw data. I have deconstructed this problem so far as to find that mongo is not even returning an object. How do I make this work without implementing a full-on REST server?