add getUserId API endpoint

This commit is contained in:
Andrew Zhu
2019-02-05 13:08:28 -08:00
parent 3f32535666
commit b94f5ebb4b
2 changed files with 24 additions and 0 deletions

1
app/.gitignore vendored
View File

@@ -8,3 +8,4 @@ private/oldClient
nohup.out
node_modules
dump
.idea/

View File

@@ -42,6 +42,29 @@ Router.map(function() {
);
},
});
this.route("getUserId", { // GET /api/user?username=:un
path: "/api/user",
where: "server",
action: function () {
this.response.setHeader("Content-Type", "application/json");
var query = this.params.query;
var key = query && query.key;
var username = query && query.username;
ifKeyValid(key, this.response, "getUserId", () => {
Meteor.call("getUserId", username, (err, result) => {
if (err) {
console.error(err);
this.response.writeHead(404, "User not found");
this.response.end();
} else {
console.log(result);
this.response.end(JSON.stringify({id: result}));
}
});
});
}
});
});
var ifKeyValid = function(apiKey, response, method, callback){