turbo-express-js 1.0.2 → 1.0.3
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.
- package/index.test.js +66 -0
- package/lib/TurboServer.js +18 -0
- package/package.json +1 -1
package/index.test.js
CHANGED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const TurboExpress = require("./lib/TurboServer");
|
|
2
|
+
const RequestInterface = require("./lib/types/RequestInterface");
|
|
3
|
+
const ResponseInterface = require("./lib/types/ResponseInterface");
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const app = new TurboExpress(2);
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
TurboExpress.exeWorker(async () =>
|
|
11
|
+
{
|
|
12
|
+
console.log("Hey")
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
TurboExpress.exeMaster(async () =>
|
|
17
|
+
{
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
console.log("Hello world");
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class MyResponse extends ResponseInterface
|
|
27
|
+
{
|
|
28
|
+
mymethod () {
|
|
29
|
+
console.log("my method")
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
app.Response = MyResponse;
|
|
34
|
+
|
|
35
|
+
app.use("/*", TurboExpress.Cors({
|
|
36
|
+
origins: ["http://localhost:3000"]
|
|
37
|
+
}));
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @param {RequestInterface} req
|
|
41
|
+
* @param {ResponseInterface} res
|
|
42
|
+
*/
|
|
43
|
+
function homepage (req, res) {
|
|
44
|
+
console.log("controller")
|
|
45
|
+
res.header("something", "wowowowo")
|
|
46
|
+
res.status(200).json({ user: { username: "kristina" } })
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const router = new TurboExpress.Router();
|
|
50
|
+
router.use("/*", TurboExpress.Cors({}))
|
|
51
|
+
router.get("/something", homepage)
|
|
52
|
+
|
|
53
|
+
app.use("", router);
|
|
54
|
+
|
|
55
|
+
app.get("/something1", homepage);
|
|
56
|
+
// app.options("/something", (req, res) => res.send(""));
|
|
57
|
+
// app.head("/something", (req, res) => res.send(""));
|
|
58
|
+
// app.get("/", homepage);
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
// app.all("/*", (req, res) => {
|
|
62
|
+
// res.send("not")
|
|
63
|
+
// })
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
app.listen(3001, () => console.log("Server is running on port 3000"));
|
package/lib/TurboServer.js
CHANGED
|
@@ -184,6 +184,19 @@ module.exports = class TurboServer
|
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
+
/**
|
|
188
|
+
* Execute code only in master instance
|
|
189
|
+
*
|
|
190
|
+
* @param {Function} cb
|
|
191
|
+
*/
|
|
192
|
+
static async exeWorker (cb)
|
|
193
|
+
{
|
|
194
|
+
if(cluster.isWorker)
|
|
195
|
+
{
|
|
196
|
+
await cb();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
187
200
|
|
|
188
201
|
|
|
189
202
|
/** @type{http.Server} */ #server;
|
|
@@ -305,6 +318,11 @@ module.exports = class TurboServer
|
|
|
305
318
|
|
|
306
319
|
}
|
|
307
320
|
|
|
321
|
+
/** @returns {http.Server} */
|
|
322
|
+
getServer () {
|
|
323
|
+
return this.#server;
|
|
324
|
+
}
|
|
325
|
+
|
|
308
326
|
|
|
309
327
|
logRoutes ()
|
|
310
328
|
{
|