-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (55 loc) · 1.42 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const {
patchUser,
postUser,
getUsers,
deleteUser,
} = require('./src/users/controllers')
const decodeToken = require('./src/middleware/auth')
const { postLogin, getUser } = require('./src/auth/controllers')
/**
* HTTP Cloud Function.
*
* @param {Object} req Cloud Function request context.
* More info: https://expressjs.com/en/api.html#req
* @param {Object} res Cloud Function response context.
* More info: https://expressjs.com/en/api.html#res
*/
exports.userApi = (req, res) => {
switch (req.method) {
case 'GET':
return getUsers(req, res)
case 'POST':
return postUser(req, res)
case 'PATCH':
return decodeToken(patchUser(req, res))
case 'DELETE':
return decodeToken(deleteUser(req, res))
default:
return res.status(405).send(`${req.method} is not allowed.`)
}
}
exports.authApi = (req, res) => {
switch (req.method) {
case 'GET':
return getUser(req, res)
case 'POST':
return postLogin(req, res)
default:
return res.json({
message: 'Please enter email and password to be authenticated.',
})
}
}
exports.helloHttp = (req, res) => {
switch (req.method) {
case 'GET':
res.status(200).send('Hello World!')
break
case 'PUT':
res.status(403).send('Forbidden!')
break
default:
res.status(405).send({ error: 'Something blew up!' })
break
}
}