Tuesday 16 May 2017

How do I prevent my API page from being viewed, yet still allow AJAX requests to it?

The code for my API page looks something like this:app.get('/api/users', function(req, res, next) { User.find().exec(function(err, users) { return res.send(users); }); }); It returns JSON data, and then I can make an AJAX request for that data on the front end. But if I got http://localhost:3000/api/users, it shows the JSON data in the browser.Is there any way to prevent this data from being displayed in the browser yet still provide the data for my AJAX calls?I'm using Express, by the way.

Submitted May 16, 2017 at 11:11PM by Torus8

No comments:

Post a Comment