Beginner in Node.js/Express, I want my front end to fetch some data from an endpoint ('/1'
) but I don't want a user to see the JSON data when they visit that endpoint. Any help would be appreciated.
app.js
var express = require('express');
var app = express();
var PORT = process.env.PORT || 3000;
app.use("/static", express.static('./static/'));
app.get('/', function(req, res) {
res.sendFile(__dirname + '/index.html')
});
app.use('/1', function(req, res, next) {
res.status(404).send('Data not available to end user');
})
app.get('/1', function(req, res) {
res.json({
"employees": [
{ "firstName":"John" , "lastName":"Doe" },
{ "firstName":"Anna" , "lastName":"Smith" },
{ "firstName":"Peter" , "lastName":"Jones" }
]
})
});
app.listen(PORT);