-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.js
34 lines (32 loc) · 1.28 KB
/
index.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
const registerService = require('./service/register');
const loginService = require('./service/login');
const verifyService = require('./service/verify');
const util = require('./utils/util');
const healthPath = '/health';
const registerPath = '/register';
const loginPath = '/login';
const verifyPath = '/verify';
exports.handler = async (event) => {
console.log('Request Event: ', event);
let response;
switch(true) {
case event.httpMethod === 'GET' && event.path === healthPath:
response = util.buildResponse(200);
break;
case event.httpMethod === 'POST' && event.path === registerPath:
const registerBody = JSON.parse(event.body);
response = await registerService.register(registerBody);
break;
case event.httpMethod === 'POST' && event.path === loginPath:
const loginBody = JSON.parse(event.body);
response = await loginService.login(loginBody);
break;
case event.httpMethod === 'POST' && event.path === verifyPath:
const verifyBody = JSON.parse(event.body);
response = verifyService.verify(verifyBody);
break;
default:
response = util.buildResponse(404, '404 Not Found');
}
return response;
};