turbo-express-js 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,65 @@
1
+ /**
2
+ * -->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>
3
+ *
4
+ * @PerfecTEvolutioN
5
+ * @project - TurboExpress
6
+ * @name ServerCallback
7
+ * @namespace TurboExpress::ServerCallback
8
+ * @license - MIT
9
+ * @author - Mike Karypidis
10
+ * @version - 1.0.0
11
+ * @link - https://npmjs.com/TurboExpress
12
+ * @github - https://github.com/TurboExpress
13
+ *
14
+ * -->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>
15
+ *
16
+ * this is the primary callback that will be executed on each server connection;
17
+ * TurboExpress is written on top of nodejs<http> package, and on .createServer(...) we are passing this callback
18
+ *
19
+ */
20
+
21
+ const RequestInterface = require("./types/RequestInterface");
22
+ const ResponseInterface = require("./types/ResponseInterface");
23
+ const http = require("http");
24
+ const { matching_route, matching_nonexact_route } = require("./utils");
25
+
26
+ /**
27
+ *
28
+ * @param {http.IncomingMessage} req
29
+ * @param {http.OutgoingMessage} res
30
+ * @returns
31
+ */
32
+ module.exports = async function ServerCallback(req, res)
33
+ {
34
+ const [path, query] = req.url.split("?");
35
+
36
+ let curr = matching_route(path, this[`__${req.method.toLowerCase()}_routes`]);
37
+
38
+ if (!curr) {
39
+ curr = matching_nonexact_route(
40
+ path,
41
+ this[`__${req.method.toLowerCase()}_routes`]
42
+ );
43
+ }
44
+
45
+ if (!curr) return res.end("~ Page Not Found || 404 ~");
46
+
47
+ /** @type {RequestInterface} new instance of <T extends RequestInterface> */
48
+ const request = new this.Request(req, curr, this);
49
+
50
+ /** @type {ResponseInterface} new instance of <T extends ResponseInterface> */
51
+ const response = new this.Response(res, curr, this);
52
+
53
+ let nextRun = true; // ! also not cost performance
54
+
55
+ const next = () => nextRun = true; // ! also not cost performance *creating a new function callback for each connection *there is no need to be static
56
+
57
+ for (let i = 0; i < curr.callbacks.length; i++) {
58
+ if(!nextRun) break;
59
+ nextRun = false; // ! not cost perfomance tested with 1000 middlewares running next() function and without next function and if checks here.;
60
+ await curr.callbacks[i](request, response, next);
61
+ }
62
+
63
+ //console.log("request finished\n")
64
+
65
+ };
@@ -0,0 +1,278 @@
1
+ /**
2
+ * -->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>
3
+ *
4
+ * @PerfecTEvolutioN
5
+ * @MikeKarypidis
6
+ * @project - TurboServer
7
+ * @name TurboServer
8
+ * @license - MIT
9
+ * @copyright - ©2022 PerfectEvolution Corporation;
10
+ * @author - Mike Karypidis
11
+ * @version - 1.0.0
12
+ * @link - https://turboserverjs.org
13
+ * @github - https://github.com/breathfunwithmindte/turbo-server.git
14
+ *
15
+ * -->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>
16
+ *
17
+ * here the primary class of TurboExpress framework - TurboServer class;
18
+ *
19
+ */
20
+
21
+ const http = require("http");
22
+ const Router = require("./Router");
23
+ const cluster = require("cluster");
24
+ const RequestInterface = require("./types/RequestInterface");
25
+ const ResponseInterface = require("./types/ResponseInterface");
26
+ const { matching_route, matching_nonexact_route } = require("./utils");
27
+ const Route = require("./types/Route");
28
+ const Middleware= require("./types/Middleware");
29
+ const RequestMethods = require("./statictypes/RequestMethods");
30
+ const ServerCallback = require("./ServerCallback");
31
+ const static_middleware = require("./middlewares/static_middleware");
32
+ const attachment_middleware = require("./middlewares/attachment_middleware");
33
+ const ValidationSchema = require("./types/ValidationSchema");
34
+ const ValidationMethodType = require("./enum/ValidationMethodType");
35
+ const validation_middleware = require("./middlewares/validation_middleware");
36
+ const runmethod_middleware = require("./middlewares/runmethod_middleware");
37
+ const buildform_middleware = require("./middlewares/buildform_middleware");
38
+ const authentication_middleware = require("./middlewares/authentication_middleware");
39
+ const cors_middleware = require("./middlewares/cors_middleware");
40
+
41
+
42
+ module.exports = class TurboServer
43
+ {
44
+ static Router = Router;
45
+ static ValidationSchema = ValidationSchema;
46
+ static ValidationMethodType = ValidationMethodType;
47
+
48
+ /**
49
+ * @typedef {Object} StaticOptions
50
+ * @property {String} folder - default /public
51
+ * @property {Boolean} cache - default false
52
+ *
53
+ * @param {StaticOptions} StaticOptions
54
+ * @returns
55
+ */
56
+ static Static (StaticOptions={})
57
+ {
58
+ return static_middleware.bind({ folder: StaticOptions.folder || "/public", cache: StaticOptions.cache || false })
59
+ }
60
+
61
+ /**
62
+ * @typedef {Object} CorsOptions
63
+ * @property {String} folder - default /public
64
+ * @property {Boolean} cache - default false
65
+ *
66
+ * @param {CorsOptions} CorsOptions
67
+ * @returns
68
+ */
69
+ static Cors (CorsOptions)
70
+ {
71
+ return cors_middleware.bind({
72
+
73
+ })
74
+ }
75
+
76
+ /**
77
+ * @typedef {Object} AttachmentOptions
78
+ * @property {String} folder - default /storage
79
+ * @property {Boolean} memory - default true
80
+ * @property {Boolean} as_middleware - default true
81
+ *
82
+ * @param {AttachmentOptions} AttachmentOptions
83
+ * @returns
84
+ */
85
+ static Upload (AttachmentOptions={})
86
+ {
87
+ return attachment_middleware.bind({
88
+ folder: AttachmentOptions.folder || "/storage", memory: AttachmentOptions.memory || true, as_middleware: AttachmentOptions.as_middleware || true
89
+ })
90
+ }
91
+
92
+ /**
93
+ * Add validations to request instance and executes the validateData method of the same instance.
94
+ * If there is an error, it throws the response with that error.
95
+ *
96
+ * @typedef {Object} ValidationOptions
97
+ * @property {ValidationSchema[]} validations
98
+ *
99
+ * @param {ValidationOptions} ValidationOptions
100
+ * @returns
101
+ */
102
+ static Validation (ValidationOptions={})
103
+ {
104
+ return validation_middleware.bind({
105
+ validations: ValidationOptions.validations
106
+ })
107
+ }
108
+
109
+ /**
110
+ * @typedef {Object} ExeMethodType
111
+ * @property {string} belong
112
+ * @property {string} methodname
113
+ * @property {*} inject
114
+ * @property {boolean} isAsync
115
+ *
116
+ * @typedef {Object} RunMethodOptions
117
+ * @property {ExeMethodType[]} exe
118
+ *
119
+ * @param {RunMethodOptions} RunMethodOptions
120
+ * @returns
121
+ */
122
+ static RunMethod (RunMethodOptions={})
123
+ {
124
+ return runmethod_middleware.bind({
125
+ exe: RunMethodOptions.exe
126
+ })
127
+ }
128
+
129
+ /**
130
+ *
131
+ * @typedef {Object} AuthenticationOptions
132
+ *
133
+ * @param {AuthenticationOptions} AuthenticationOptions
134
+ * @returns
135
+ */
136
+ static Authentication (AuthenticationOptions={})
137
+ {
138
+ return authentication_middleware.bind({
139
+
140
+ })
141
+ }
142
+
143
+ /**
144
+ * @typedef {Object} BuildFormOptions
145
+ *
146
+ * @param {BuildFormOptions} BuildFormOptions
147
+ * @returns
148
+ */
149
+ static BuildForm (BuildFormOptions={})
150
+ {
151
+ return buildform_middleware.bind({
152
+
153
+ })
154
+ }
155
+
156
+
157
+
158
+ /** @type{http.Server} */ #server;
159
+
160
+ // spliting the list of routes base on method, so later have less items in list to search for each connection
161
+ /** @type{Route[]} */ __get_routes = [];
162
+ /** @type{Route[]} */ __post_routes = [];
163
+ /** @type{Route[]} */ __put_routes = [];
164
+ /** @type{Route[]} */ __delete_routes = [];
165
+ /** @type{Route[]} */ __head_routes = [];
166
+ /** @type{Route[]} */ __patch_routes = [];
167
+ /** @type{Route[]} */ __options_routes = [];
168
+ /** @type{Route[]} */ __link_routes = [];
169
+ /** @type{Route[]} */ __unlink_routes = [];
170
+ /** @type{Route[]} */ __view_routes = [];
171
+ /** @type{Route[]} */ __lock_routes = [];
172
+ /** @type{Route[]} */ __unlock_routes = [];
173
+ /** @type{Route[]} */ __copy_routes = [];
174
+ /** @type{Route[]} */ __purge_routes = [];
175
+ /** @type{Route[]} */ __propfind_routes = [];
176
+
177
+ /** @type{Middleware[]} */ __middlewares_begin = [];
178
+ /** @type{Middleware[]} */ __middlewares_end = [];
179
+
180
+ // * interfaces
181
+ /** @type{RequestInterface} */ Request;
182
+ /** @type{ResponseInterface} */ Response;
183
+
184
+ /** @type {Map<String, Object>} */ appState = new Map();
185
+ /** @type {Map<String, import("mongoose").Model} */ models = new Map();
186
+ /** @type {Map<String, import("mongoose").Model} */ sqlModels = new Map(); // TODO later
187
+
188
+ /**
189
+ * @param {Number} CLUSTERSLENGTH
190
+ * @doc - here on constructor will be created a server instance;
191
+ * createServer method of http class will get the primary servercallback and bind this of current instance;
192
+ * the method listen of current instance should be invoked to listen on some port;
193
+ */
194
+ constructor (CLUSTERSLENGTH)
195
+ {
196
+ if (cluster.isMaster) {
197
+ for (let i = 0; i < CLUSTERSLENGTH; i++) { cluster.fork() }
198
+ } else {
199
+ global["TurboExpress"] = new Object();
200
+ global["TurboExpressCaching"] = new Object();
201
+ this.#server = http.createServer(ServerCallback.bind(this));
202
+ this.Request = RequestInterface;
203
+ this.Response = ResponseInterface;
204
+ }
205
+ }
206
+
207
+ get(path, ...callbacks){if(!cluster.isMaster) {this.__get_routes.push(new Route(path, RequestMethods.GET, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
208
+ post(path, ...callbacks){if(!cluster.isMaster) {this.__post_routes.push(new Route(path, RequestMethods.POST, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
209
+ put(path, ...callbacks){if(!cluster.isMaster) {this.__put_routes.push(new Route(path, RequestMethods.PUT, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
210
+ delete(path, ...callbacks){if(!cluster.isMaster) {this.__delete_routes.push(new Route(path, RequestMethods.DELETE, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
211
+ head(path, ...callbacks){if(!cluster.isMaster) {this.__head_routes.push(new Route(path, RequestMethods.HEAD, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
212
+ patch(path, ...callbacks){if(!cluster.isMaster) {this.__patch_routes.push(new Route(path, RequestMethods.PATCH, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
213
+ options(path, ...callbacks){if(!cluster.isMaster) {this.__options_routes.push(new Route(path, RequestMethods.OPTIONS, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
214
+ link(path, ...callbacks){if(!cluster.isMaster) {this.__link_routes.push(new Route(path, RequestMethods.LINK, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
215
+ unlink(path, ...callbacks){if(!cluster.isMaster) {this.__unlink_routes.push(new Route(path, RequestMethods.UNLINK, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
216
+ view(path, ...callbacks){if(!cluster.isMaster) {this.__view_routes.push(new Route(path, RequestMethods.VIEW, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
217
+ lock(path, ...callbacks){if(!cluster.isMaster) {this.__lock_routes.push(new Route(path, RequestMethods.LOCK, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
218
+ unlock(path, ...callbacks){if(!cluster.isMaster) {this.__unlock_routes.push(new Route(path, RequestMethods.UNLOCK, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
219
+ copy(path, ...callbacks){if(!cluster.isMaster) {this.__copy_routes.push(new Route(path, RequestMethods.COPY, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
220
+ purge(path, ...callbacks){if(!cluster.isMaster) {this.__purge_routes.push(new Route(path, RequestMethods.PURGE, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
221
+ propfind(path, ...callbacks){if(!cluster.isMaster) {this.__propfind_routes.push(new Route(path, RequestMethods.PROPFIND, callbacks, this.__middlewares_begin, this.__middlewares_end));}}
222
+
223
+ use(path, ...callbackOrRouter)
224
+ {
225
+ if(callbackOrRouter[0] instanceof Router === true) {
226
+ callbackOrRouter[0].inject(path, this);
227
+ } else {
228
+ this.__middlewares_begin.push(new Middleware(path, callbackOrRouter));
229
+ }
230
+ }
231
+
232
+ useEndMiddleware (path, ...callbacks)
233
+ {
234
+ this.__middlewares_end.push(new Middleware(path, callbacks));
235
+ }
236
+
237
+
238
+
239
+ /**
240
+ * todo method for deleting routes in runtime.
241
+ * can be used inside controllers - dynamic change routes from: example: server admin panel
242
+ *
243
+ * @param {String} method
244
+ * @param {String} path
245
+ */
246
+ deleteRoute (method, path) {
247
+
248
+ }
249
+
250
+ /**
251
+ * todo method for find route in runtime.
252
+ * can be used inside controllers - dynamic change routes from: example: server admin panel
253
+ *
254
+ * @param {String} method
255
+ * @param {String} path
256
+ */
257
+ getRoute (method, path) {
258
+
259
+ }
260
+
261
+
262
+
263
+
264
+ logRoutes ()
265
+ {
266
+ let arr = [...this.__get_routes, ...this.__post_routes, ...this.__put_routes, ...this.__delete_routes];
267
+ console.table(arr);
268
+ }
269
+
270
+ listen (port, cb)
271
+ {
272
+ /** will listen not on master cluster ... */
273
+ if(!cluster.isMaster) {
274
+ this.#server.listen(port, cb ? cb : () => console.log("server is running"))
275
+ }
276
+ }
277
+
278
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ *
3
+ * @param {String} fileName
4
+ * @returns {String | null}
5
+ */
6
+ module.exports = (fileName) => {
7
+ switch ("." + fileName.split(".")[fileName.split(".").length - 1]) {
8
+ case ".pdf": return "application/pdf";
9
+ case ".doc": return "application/msword";
10
+ case ".xls": return "application/vnd.ms-excel";
11
+ case ".ppt": return "application/vnd.ms-powerpoint";
12
+ case ".zip": return "application/zip";
13
+ case ".mp3": return "audio/mpeg";
14
+ case ".ogg": return "audio/ogg";
15
+ case ".wav": return "audio/x-wav";
16
+ case ".csv": return "text/csv";
17
+ case ".html": return "text/html";
18
+ case ".txt": return "text/plain";
19
+ case ".bmp": return "image/bmp";
20
+ case ".gif": return "image/gif";
21
+ case ".jpg": return "image/jpeg";
22
+ case ".jpeg": return "image/jpeg";
23
+ case ".png": return "image/png";
24
+ case ".mp4": return "video/mp4";
25
+ case ".webm": return "video/webm";
26
+ case ".swf": return "application/x-shockwave-flash";
27
+ case ".tar": return "application/x-tar";
28
+ case ".gz": return "application/x-gzip";
29
+ case ".7z": return "application/x-7z-compressed";
30
+ case ".rar": return "application/x-rar-compressed";
31
+ case ".exe": return "application/octet-stream";
32
+ case ".json": return "application/json";
33
+ default: return null;
34
+ }
35
+ }
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ "MINLENGTH": "minlength",
3
+ "MAXLENGTH": "maxlength",
4
+ "ONEOF": "oneof",
5
+ "SIZE": "size"
6
+ }
@@ -0,0 +1,89 @@
1
+ /**
2
+ * -->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>
3
+ *
4
+ * @PerfecTEvolutioN
5
+ * @project - TurboExpress
6
+ * @name TurboExpress
7
+ * @namespace TurboExpress::middlewares::static_middleware
8
+ * @license - MIT
9
+ * @author - Mike Karypidis
10
+ * @version - 1.0.0
11
+ * @link - https://npmjs.com/TurboExpress
12
+ * @github - https://github.com/TurboExpress
13
+ *
14
+ * -->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>
15
+ */
16
+
17
+ const FileType = require("../types/FileType");
18
+ const RequestInterface = require("../types/RequestInterface");
19
+ const ResponseInterface = require("../types/ResponseInterface");
20
+ const multiparty = require("multiparty")
21
+
22
+ /**
23
+ *
24
+ * @param {RequestInterface} req
25
+ * @param {ResponseInterface} res
26
+ * @param {*} next
27
+ */
28
+ module.exports = function attachment_middleware (req, res, next)
29
+ {
30
+ console.log("attachment middleware");
31
+
32
+ const { memory, folder } = this;
33
+ console.log(memory, folder);
34
+
35
+ const httpRequest = req.IncomingMessage; //http.IncomingMessage
36
+ const httpResponse = res.OutgoingMessage; //http.OutgoingMessage
37
+
38
+ const files = new Array();
39
+
40
+ if(memory)
41
+ {
42
+ /** @type{Buffer[]} */ const FilesBuffers = new Array();
43
+ const form = new multiparty.Form({ autoFields: true });
44
+
45
+ form.on("part", (part) => {
46
+ let buffer = Buffer.alloc(0);
47
+ const mine_type = part.headers["content-type"] || "";
48
+ const turboExpressFile = new FileType();
49
+ turboExpressFile.name = part.name;
50
+ turboExpressFile.fileName = part.filename;
51
+ turboExpressFile.is_binary = true;
52
+ turboExpressFile.is_compressible = false;
53
+ turboExpressFile.is_encrypted = false;
54
+ turboExpressFile.extension = mine_type.split("/")[1] || "not-found"
55
+ turboExpressFile.mime_type = mine_type;
56
+ turboExpressFile.buffer_size = part.byteCount;
57
+ turboExpressFile.metadata = {}
58
+ turboExpressFile.description = `File with name = {${turboExpressFile.fileName}}, sent with name = {${turboExpressFile.name}} and stored into server memory;`
59
+ turboExpressFile.owner = null;
60
+
61
+ console.log(turboExpressFile)
62
+
63
+ part.on("data", (chunk) => {
64
+ console.log("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
65
+ buffer = Buffer.concat([buffer, chunk]);
66
+ })
67
+
68
+ part.on("end", () => {
69
+ console.log("ennennenen")
70
+ turboExpressFile.buffer = buffer;
71
+ turboExpressFile.buffer_size = buffer.length;
72
+ req._files.push(turboExpressFile);
73
+ })
74
+
75
+ })
76
+ form.parse(req.IncomingMessage);
77
+
78
+ form.on("close", () => {
79
+ console.log(req._files, "@@@")
80
+ })
81
+
82
+ }
83
+ else
84
+ {
85
+ throw new Error("Currently method to store files not in memory and handle large files, is not implemented.")
86
+ }
87
+
88
+
89
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * -->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>
3
+ *
4
+ * @PerfecTEvolutioN
5
+ * @project - TurboExpress
6
+ * @name TurboExpress
7
+ * @namespace TurboExpress::middlewares::authentication_middleware
8
+ * @license - MIT
9
+ * @author - Mike Karypidis
10
+ * @version - 1.0.0
11
+ * @link - https://npmjs.com/TurboExpress
12
+ * @github - https://github.com/TurboExpress
13
+ *
14
+ * -->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>
15
+ */
16
+
17
+ const RequestInterface = require("../types/RequestInterface");
18
+ const ResponseInterface = require("../types/ResponseInterface");
19
+
20
+ /**
21
+ *
22
+ * @param {RequestInterface} req
23
+ * @param {ResponseInterface} res
24
+ * @param {*} next
25
+ */
26
+ module.exports = function authentication_middleware (req, res, next)
27
+ {
28
+
29
+ // comming soon;
30
+
31
+ res.send("comming soon - authentication middleware");
32
+
33
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * -->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>
3
+ *
4
+ * @PerfecTEvolutioN
5
+ * @project - TurboExpress
6
+ * @name TurboExpress
7
+ * @namespace TurboExpress::middlewares::authentication_middleware
8
+ * @license - MIT
9
+ * @author - Mike Karypidis
10
+ * @version - 1.0.0
11
+ * @link - https://npmjs.com/TurboExpress
12
+ * @github - https://github.com/TurboExpress
13
+ *
14
+ * -->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>
15
+ */
16
+
17
+ const RequestInterface = require("../types/RequestInterface");
18
+ const ResponseInterface = require("../types/ResponseInterface");
19
+
20
+ /**
21
+ *
22
+ * @param {RequestInterface} req
23
+ * @param {ResponseInterface} res
24
+ * @param {*} next
25
+ */
26
+ module.exports = function buildform_middleware (req, res, next)
27
+ {
28
+
29
+ // comming soon;
30
+
31
+ res.send("comming soon - buildform middleware");
32
+
33
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * -->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>
3
+ *
4
+ * @PerfecTEvolutioN
5
+ * @project - TurboExpress
6
+ * @name TurboExpress
7
+ * @namespace TurboExpress::middlewares::static_middleware
8
+ * @license - MIT
9
+ * @author - Mike Karypidis
10
+ * @version - 1.0.0
11
+ * @link - https://npmjs.com/TurboExpress
12
+ * @github - https://github.com/TurboExpress
13
+ *
14
+ * -->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>
15
+ */
16
+
17
+ const RequestInterface = require("../types/RequestInterface");
18
+ const ResponseInterface = require("../types/ResponseInterface");
19
+
20
+ /**
21
+ *
22
+ * @param {RequestInterface} req
23
+ * @param {ResponseInterface} res
24
+ * @param {*} next
25
+ */
26
+ module.exports = function cors_middleware (req, res, next)
27
+ {
28
+
29
+ // comming soon;
30
+
31
+ res.send("comming soon - cors middleware");
32
+
33
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * -->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>
3
+ *
4
+ * @PerfecTEvolutioN
5
+ * @project - TurboExpress
6
+ * @name TurboExpress
7
+ * @namespace TurboExpress::middlewares::static_middleware
8
+ * @license - MIT
9
+ * @author - Mike Karypidis
10
+ * @version - 1.0.0
11
+ * @link - https://npmjs.com/TurboExpress
12
+ * @github - https://github.com/TurboExpress
13
+ *
14
+ * -->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>
15
+ */
16
+
17
+ const RequestInterface = require("../types/RequestInterface");
18
+ const ResponseInterface = require("../types/ResponseInterface");
19
+
20
+ /**
21
+ *
22
+ * @param {RequestInterface} req
23
+ * @param {ResponseInterface} res
24
+ * @param {*} next
25
+ */
26
+ module.exports = async function runmethod_middleware (req, res, next)
27
+ {
28
+ let continueExecuting = true;
29
+ const nextExe = () => continueExecuting = true;
30
+
31
+ for (let index = 0; index < this.exe.length; index++) {
32
+ if(continueExecuting === false) break;
33
+ continueExecuting = false;
34
+ //console.log(this.exe[index]);
35
+ if(this.exe[index].isAsync) {
36
+ if(this.exe[index].belong === "req") {
37
+ await req[this.exe[index].methodname](res, this.exe[index].inject, nextExe)
38
+ } else {
39
+ await res[this.exe[index].methodname](req, this.exe[index].inject, nextExe)
40
+ }
41
+ } else {
42
+ if(this.exe[index].belong === "req") {
43
+ req[this.exe[index].methodname](res, this.exe[index].inject, nextExe)
44
+ } else {
45
+ res[this.exe[index].methodname](req, this.exe[index].inject, nextExe)
46
+ }
47
+ }
48
+
49
+ }
50
+ if(continueExecuting) next()
51
+ }