-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.js
74 lines (65 loc) · 1.46 KB
/
handler.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"use strict";
const list = require('./routes/list').handle;
const check = require('./routes/check').handle;
const history = require('./routes/history').handle;
const info = require('./routes/info').handle;
module.exports.route = async (event) => {
if(event.requestContext === undefined
|| event.requestContext.http === undefined
|| event.requestContext.http.path === undefined
) return {
statusCode: 400,
body: JSON.stringify(
{
success: false,
message: "Missing HTTP Context",
},
null,
2
),
};
const path = event.requestContext.http.path.toLowerCase();
if(path === '/') return {
statusCode: 200,
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(
{
success: true,
version: 1.0,
message: "Litebans API by Captain_Sisko",
github: "https://github.com/left4craft/litebans-serverless"
},
null,
2
),
};
if (path === '/list') {
return list(event);
}
if (path === '/check') {
return check(event);
}
if (path === '/history') {
return history(event);
}
if (path === '/info') {
return info(event);
}
return {
statusCode: 404,
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(
{
success: false,
message: "No such route",
path: path
},
null,
2
),
};
};