@dim24/servin 0.0.0-stage → 0.2.1
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/LICENSE +21 -0
- package/README.md +1625 -3
- package/example/index.js +43 -0
- package/example/router.js +11 -0
- package/index.js +3 -0
- package/package.json +38 -4
- package/src/server.js +1022 -0
- package/src/servin.test.js +108 -0
- package/src/session.js +311 -0
- package/src/tree.js +703 -0
- package/src/utils.js +559 -0
- package/src/websocket.js +311 -0
- package/src/wire.js +275 -0
- package/test.js +45 -0
package/example/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
|
|
2
|
+
import { serve, param, wire } from "../index.js";
|
|
3
|
+
|
|
4
|
+
const tasksDb = new Map([
|
|
5
|
+
[1, { id: 1, title: "Design domain tree", priority: "high", done: true }],
|
|
6
|
+
[
|
|
7
|
+
2,
|
|
8
|
+
{
|
|
9
|
+
id: 2,
|
|
10
|
+
title: "Write integration tests",
|
|
11
|
+
priority: "medium",
|
|
12
|
+
done: false,
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
await serve({
|
|
18
|
+
port: 3000,
|
|
19
|
+
api: {
|
|
20
|
+
// GET /health
|
|
21
|
+
health: {
|
|
22
|
+
get: () => ({ status: "ok" }),
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
// GET /tasks?done=false
|
|
26
|
+
tasks: {
|
|
27
|
+
get(query) {
|
|
28
|
+
let list = [...tasksDb.values()];
|
|
29
|
+
if (query.done === "true") list = list.filter((t) => t.done);
|
|
30
|
+
if (query.done === "false") list = list.filter((t) => !t.done);
|
|
31
|
+
return list;
|
|
32
|
+
},
|
|
33
|
+
$id: param('int', {
|
|
34
|
+
// GET /tasks/:id
|
|
35
|
+
get(id) {
|
|
36
|
+
const task = tasksDb.get(id);
|
|
37
|
+
if (!task) wire.abort(404, `Task #${id} not found`);
|
|
38
|
+
return task;
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
});
|
package/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dim24/servin",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "A modern, zero-dependency JavaScript web server built around *Domain-Tree Projection.",
|
|
5
|
+
"homepage": "https://github.com/harakun24/servin#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/harakun24/servin/issues"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/harakun24/servin.git"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "Abista, V. D.",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "index.js",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": "./index.js",
|
|
19
|
+
"./test": "./test.js"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"test": "node --test tests/servin.test.js"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"web-server",
|
|
26
|
+
"http-server",
|
|
27
|
+
"web-framework",
|
|
28
|
+
"server",
|
|
29
|
+
"api",
|
|
30
|
+
"nodejs",
|
|
31
|
+
"esm",
|
|
32
|
+
"domain-tree",
|
|
33
|
+
"websocket",
|
|
34
|
+
"sse",
|
|
35
|
+
"server-sent-events",
|
|
36
|
+
"session",
|
|
37
|
+
"caching",
|
|
38
|
+
"virtual-client"
|
|
39
|
+
]
|
|
40
|
+
}
|