express-speed 1.0.6 → 1.0.7
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/README.md +69 -79
- package/package.json +1 -1
- package/src/expressSpeed.js +12 -9
package/README.md
CHANGED
|
@@ -21,7 +21,45 @@ npm install express-speed
|
|
|
21
21
|
|
|
22
22
|
---
|
|
23
23
|
|
|
24
|
-
##
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
import { expressSpeed } from "express-speed";
|
|
28
|
+
|
|
29
|
+
expressSpeed.listen(80, {
|
|
30
|
+
page: {
|
|
31
|
+
render: ["./page/**/*.js"],
|
|
32
|
+
exclude: [],
|
|
33
|
+
nodir: true,
|
|
34
|
+
},
|
|
35
|
+
use: [
|
|
36
|
+
(req, res, next) => {
|
|
37
|
+
console.log("request received");
|
|
38
|
+
next();
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
settings: {
|
|
42
|
+
"view engine": "pug",
|
|
43
|
+
views: "./pug",
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### `expressSpeed.listen` Options
|
|
49
|
+
|
|
50
|
+
| Key | Type | Description |
|
|
51
|
+
|-----|------|-------------|
|
|
52
|
+
| `page.render` | `string[]` | Glob patterns to match page files |
|
|
53
|
+
| `page.exclude` | `string[]` | Glob patterns to exclude |
|
|
54
|
+
| `page.nodir` | `boolean` | Skip directories |
|
|
55
|
+
| `use` | `function[]` | Global middleware applied to all routes |
|
|
56
|
+
| `settings` | `object` | Express app settings (`view engine`, `views`, etc.) |
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Usage
|
|
61
|
+
|
|
62
|
+
### Basic Page
|
|
25
63
|
|
|
26
64
|
```js
|
|
27
65
|
import { pager } from "express-speed";
|
|
@@ -37,9 +75,7 @@ let page = pager
|
|
|
37
75
|
export default page;
|
|
38
76
|
```
|
|
39
77
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
## Multiple Handlers
|
|
78
|
+
### Multiple Handlers
|
|
43
79
|
|
|
44
80
|
You can define multiple handlers for the same route.
|
|
45
81
|
|
|
@@ -58,40 +94,7 @@ export default pager
|
|
|
58
94
|
.build();
|
|
59
95
|
```
|
|
60
96
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
## Sub Path Routes
|
|
64
|
-
|
|
65
|
-
Use `get(path, handler)` to create different endpoints within the same pager.
|
|
66
|
-
|
|
67
|
-
```js
|
|
68
|
-
import { pager } from "express-speed";
|
|
69
|
-
|
|
70
|
-
export default pager
|
|
71
|
-
.url("/blog")
|
|
72
|
-
.get((req, res) => {
|
|
73
|
-
res.send("Blog Home");
|
|
74
|
-
})
|
|
75
|
-
.get("/blog/post/:id", (req, res) => {
|
|
76
|
-
res.send(`Post ${req.params.id}`);
|
|
77
|
-
})
|
|
78
|
-
.get("/blog/latest", (req, res) => {
|
|
79
|
-
res.send("Latest posts");
|
|
80
|
-
})
|
|
81
|
-
.build();
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
Generated routes:
|
|
85
|
-
|
|
86
|
-
```
|
|
87
|
-
/blog
|
|
88
|
-
/blog/post/:id
|
|
89
|
-
/blog/latest
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
---
|
|
93
|
-
|
|
94
|
-
## Middleware Usage
|
|
97
|
+
### Middleware
|
|
95
98
|
|
|
96
99
|
```js
|
|
97
100
|
import { pager } from "express-speed";
|
|
@@ -110,9 +113,7 @@ export default pager
|
|
|
110
113
|
.build();
|
|
111
114
|
```
|
|
112
115
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
## Role Based Access
|
|
116
|
+
### Role Based Access
|
|
116
117
|
|
|
117
118
|
```js
|
|
118
119
|
import { pager } from "express-speed";
|
|
@@ -126,62 +127,51 @@ export default pager
|
|
|
126
127
|
.build();
|
|
127
128
|
```
|
|
128
129
|
|
|
129
|
-
|
|
130
|
+
### Sub Path Routes
|
|
130
131
|
|
|
131
|
-
|
|
132
|
+
Use `get(path, handler)` to create different endpoints within the same pager.
|
|
132
133
|
|
|
133
134
|
```js
|
|
134
135
|
import { pager } from "express-speed";
|
|
135
136
|
|
|
136
137
|
export default pager
|
|
137
|
-
.url("/
|
|
138
|
-
.get(
|
|
139
|
-
res.
|
|
138
|
+
.url("/blog")
|
|
139
|
+
.get((req, res) => {
|
|
140
|
+
res.send("Blog Home");
|
|
140
141
|
})
|
|
141
|
-
.get("/
|
|
142
|
-
res.
|
|
142
|
+
.get("/blog/post/:id", (req, res) => {
|
|
143
|
+
res.send(`Post ${req.params.id}`);
|
|
144
|
+
})
|
|
145
|
+
.get("/blog/latest", (req, res) => {
|
|
146
|
+
res.send("Latest posts");
|
|
143
147
|
})
|
|
144
148
|
.build();
|
|
145
149
|
```
|
|
146
150
|
|
|
147
|
-
|
|
151
|
+
Generated routes:
|
|
148
152
|
|
|
149
|
-
|
|
153
|
+
```
|
|
154
|
+
/blog
|
|
155
|
+
/blog/post/:id
|
|
156
|
+
/blog/latest
|
|
157
|
+
```
|
|
150
158
|
|
|
151
|
-
|
|
159
|
+
### Router Style
|
|
152
160
|
|
|
153
161
|
```js
|
|
154
|
-
import {
|
|
162
|
+
import { pager } from "express-speed";
|
|
155
163
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
next();
|
|
166
|
-
},
|
|
167
|
-
],
|
|
168
|
-
settings: {
|
|
169
|
-
"view engine": "pug",
|
|
170
|
-
views: "./pug",
|
|
171
|
-
},
|
|
172
|
-
});
|
|
164
|
+
export default pager
|
|
165
|
+
.url("/api")
|
|
166
|
+
.get("/users", (req, res) => {
|
|
167
|
+
res.json(["user1", "user2"]);
|
|
168
|
+
})
|
|
169
|
+
.get("/products", (req, res) => {
|
|
170
|
+
res.json(["product1", "product2"]);
|
|
171
|
+
})
|
|
172
|
+
.build();
|
|
173
173
|
```
|
|
174
174
|
|
|
175
|
-
### Options
|
|
176
|
-
|
|
177
|
-
| Key | Type | Description |
|
|
178
|
-
|-----|------|-------------|
|
|
179
|
-
| `page.render` | `string[]` | Glob patterns to match page files |
|
|
180
|
-
| `page.exclude` | `string[]` | Glob patterns to exclude |
|
|
181
|
-
| `page.nodir` | `boolean` | Skip directories |
|
|
182
|
-
| `use` | `function[]` | Global middleware applied to all routes |
|
|
183
|
-
| `settings` | `object` | Express app settings (`view engine`, `views`, etc.) |
|
|
184
|
-
|
|
185
175
|
---
|
|
186
176
|
|
|
187
177
|
## GraphQL Integration
|
package/package.json
CHANGED
package/src/expressSpeed.js
CHANGED
|
@@ -50,12 +50,15 @@ let expressSpeed = {
|
|
|
50
50
|
for (const router of pageObjectValue.methods) {
|
|
51
51
|
let parameters = ("string" == typeof router.parameters[0]) ? [...router.parameters] : [router.url, ...router.parameters];
|
|
52
52
|
if (app[router.method.toString().toLowerCase()]) {
|
|
53
|
-
app[router.method.toString().toLowerCase()](...parameters)
|
|
53
|
+
app[router.method.toString().toLowerCase()](...parameters);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
57
|
async load() {
|
|
58
|
-
for (const useValue of expressSpeed.config.use)
|
|
58
|
+
for (const useValue of expressSpeed.config.use) {
|
|
59
|
+
if (Array.isArray(useValue)) expressSpeed.app.use(...useValue);
|
|
60
|
+
else expressSpeed.app.use(useValue);
|
|
61
|
+
}
|
|
59
62
|
for (let [setKey, setValue] of Object.entries(expressSpeed.config.settings)) expressSpeed.app.set(setKey, setValue);
|
|
60
63
|
let pagesMap = expressSpeed.complier.pagesMap(expressSpeed.config.path.page.render, expressSpeed.config.path.page.exclude);
|
|
61
64
|
let pages = await expressSpeed.complier.pagesImport(pagesMap);
|
|
@@ -72,13 +75,13 @@ let expressSpeed = {
|
|
|
72
75
|
}) {
|
|
73
76
|
if (typeof config.go == "function") config.go(expressSpeed);
|
|
74
77
|
config.port = port;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
expressSpeed.config.path.page = {
|
|
79
|
+
...expressSpeed.config.path.page,
|
|
80
|
+
...config.page
|
|
81
|
+
} || {};
|
|
82
|
+
expressSpeed.config.port = config.port || 80;
|
|
83
|
+
expressSpeed.config.use = config.use || [];
|
|
84
|
+
expressSpeed.config.settings = config.settings || {};
|
|
82
85
|
|
|
83
86
|
expressSpeed.complier.load();
|
|
84
87
|
expressSpeed.app.listen(expressSpeed.config.port);
|