enable/disable api with env var

This commit is contained in:
guillaume 2018-07-24 18:09:30 +02:00
parent dafe1e39a5
commit 6173a73381
5 changed files with 23 additions and 3 deletions

View file

@ -622,9 +622,20 @@ if (Meteor.isServer) {
});
}
// USERS REST API
if (Meteor.isServer) {
// Middleware which checks that API is enabled.
JsonRoutes.Middleware.use(function (req, res, next) {
const api = req.url.search('api');
if (api === 1 && process.env.WITH_API === 'true' || api === -1){
return next();
}
else {
res.writeHead(301, {Location: '/'});
return res.end();
}
});
JsonRoutes.add('GET', '/api/user', function(req, res) {
try {
Authentication.checkLoggedIn(req.userId);