-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
119 lines (89 loc) · 2.42 KB
/
index.js
File metadata and controls
119 lines (89 loc) · 2.42 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
module.exports = function (data = {}) {
// Prepare Express
let app = null;
let bodyParser = null;
// Path Page
let path_page = {
post: '*',
get: '*'
};
// Exist Data
if (typeof data !== "function" && typeof data !== "undefined" && data) {
// Express
if (data.express) {
// Insert Express
app = express();
// Prepare Helmet
try {
const helmet = require('helmet');
app.use(helmet());
} catch (err) { }
// Prepare Body Parser
try {
bodyParser = require('body-parser');
} catch (err) { }
} else if (data.app) {
app = data.app;
}
// Change Path
if (data.path) {
// Change Post Path
if (typeof data.path.post === "string") {
path_page.post = data.path.post;
}
// Change Get Path
if (typeof data.path.get === "string") {
path_page.get = data.path.get;
} else if (data.path.get === null) {
path_page.get = null;
}
}
}
// Nope
else {
// Get Express
try {
express = require('express');
app = express();
} catch (err) {
express = null;
}
// Exist Express
if (express) {
// Prepare Helmet
try {
const helmet = require('helmet');
app.use(helmet());
} catch (err) { }
// Prepare Body Parser
try {
bodyParser = require('body-parser');
} catch (err) { }
}
}
// Is Function
if (typeof data === "function") {
data = { post: data };
}
// Post
if (path_page.post && typeof data.post === "function") {
// Body Parser
if (bodyParser) {
app.post(path_page.post, bodyParser.text({ type: '*/*' }), data.post);
}
// Nope
else {
app.post(path_page.post, data.post);
}
}
// Get
if (path_page.get) {
app.get(path_page.get, (req, res) => {
// HTTP Page
const http_page = require('@tinypudding/puddy-lib/http/HTTP-1.0');
return http_page.send(res, 403);
});
}
// Result
return app;
};