-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
39 lines (32 loc) · 1.27 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"use strict";
var restify = require("restify");
var controller = require("./controller");
var logger = require("./components").logger;
var server = restify.createServer({
name: "auth",
log: logger
});
server.use(restify.queryParser());
server.use(restify.bodyParser());
function processResult(handler) {
return function(req, res, next) {
Promise.resolve()
.then(() => handler(req, res))
.then(result => res.send(result))
.catch(next);
};
}
function getHealthcheck() {
return (req, res) => res.send(200);
}
server.get("/healthcheck", getHealthcheck());
server.post("/v1/register", processResult(controller.register));
server.post("/v1/resend_email_verification", processResult(controller.resendEmailVerification));
server.get("/v1/verify_email", processResult(controller.verifyEmail));
server.post("/v1/login", processResult(controller.login));
server.get("/v1/logout", processResult(controller.logout));
server.get("/v1/forgot_password", processResult(controller.forgotPassword));
server.post("/v1/reset_password", processResult(controller.resetPassword));
server.post("/v1/change_password", processResult(controller.changePassword));
server.get("/v1/internal/session", processResult(controller.session));
module.exports = server;