maxserver 0.0.17 โ 0.0.18
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 +20 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -64,7 +64,9 @@ Any fastify options can be passed to maxserver() too.
|
|
|
64
64
|
| `mongodb` | *-* | MongoDB URI, if set auto-connects db |
|
|
65
65
|
| `public` | `false` | Set `true` to expose the server publicly (binds to `0.0.0.0`) |
|
|
66
66
|
| `static` | *-* | If set, serves this directory statically |
|
|
67
|
-
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
<br>
|
|
68
70
|
|
|
69
71
|
## ๐๏ธ Project Structure
|
|
70
72
|
Our golden rule: **1 route = 1 handler file + 1 schema file**
|
|
@@ -82,21 +84,16 @@ src/
|
|
|
82
84
|
```
|
|
83
85
|
<br>
|
|
84
86
|
|
|
85
|
-
##
|
|
86
|
-
|
|
87
|
-
#### 1) Define method + path
|
|
88
|
-
Start each route file with a comment to define the path.
|
|
89
|
-
That comment is what the route loader uses to auto-register the route.
|
|
90
|
-
|
|
91
|
-
```js
|
|
92
|
-
// GET /teams/:id
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
#### 2) Export default handler
|
|
87
|
+
## ๐ค Auto Routing
|
|
96
88
|
|
|
89
|
+
To auto-register routes, simple add a comment of the form:
|
|
90
|
+
**// METHOD /path**
|
|
91
|
+
**// GET /user**
|
|
92
|
+
**// POST /feedback/something**
|
|
93
|
+
...
|
|
97
94
|
|
|
98
95
|
```js
|
|
99
|
-
// GET /
|
|
96
|
+
// GET /example/:id
|
|
100
97
|
|
|
101
98
|
export default async function (req, res) {
|
|
102
99
|
|
|
@@ -105,8 +102,11 @@ export default async function (req, res) {
|
|
|
105
102
|
return team;
|
|
106
103
|
}
|
|
107
104
|
```
|
|
108
|
-
|
|
105
|
+
<br>
|
|
106
|
+
|
|
107
|
+
And remember to use default export for your handler.
|
|
109
108
|
If you don't want to autoregister some routes, then simply don't add that magic comment ๐
|
|
109
|
+
That's it.
|
|
110
110
|
|
|
111
111
|
|
|
112
112
|
<br>
|
|
@@ -114,11 +114,11 @@ If you don't want to autoregister some routes, then simply don't add that magic
|
|
|
114
114
|
|
|
115
115
|
|
|
116
116
|
## ๐งพ Schemas
|
|
117
|
-
Create a sibling file ending with **`.schema.js`**, so it will be auto registered.
|
|
118
|
-
|
|
117
|
+
Create a sibling file ending with **`.schema.js`**, so it will be auto registered. For example: **hello.js** and **hello.schema.js**
|
|
118
|
+
|
|
119
|
+
Besides the basic validation fields we can set fields like summary and description, which will appear in the docs. Mostly you don't need to write schemas yourself, chat gpt and gemini do it excelently.
|
|
120
|
+
|
|
119
121
|
|
|
120
|
-
Besides the basic validation fields we can set fields like summary and description,
|
|
121
|
-
which will appear in the docs. Mostly you don't need to write schemas yourself, chat gpt and gemini do it excelently.
|
|
122
122
|
|
|
123
123
|
|
|
124
124
|
```js
|
|
@@ -142,7 +142,8 @@ export default {
|
|
|
142
142
|
};
|
|
143
143
|
```
|
|
144
144
|
|
|
145
|
-
|
|
145
|
+
**โผ๏ธ Important use export default
|
|
146
|
+
**
|
|
146
147
|
|
|
147
148
|
<br>
|
|
148
149
|
|