h3 1.8.0-rc.3 → 1.8.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/README.md +14 -13
- package/dist/index.cjs +209 -204
- package/dist/index.d.cts +581 -0
- package/dist/index.d.mts +581 -0
- package/dist/index.d.ts +77 -72
- package/dist/index.mjs +203 -205
- package/package.json +31 -31
package/README.md
CHANGED
|
@@ -86,7 +86,7 @@ import { createApp, eventHandler, toNodeListener } from "h3";
|
|
|
86
86
|
const app = createApp();
|
|
87
87
|
app.use(
|
|
88
88
|
"/",
|
|
89
|
-
eventHandler(() => "Hello world!")
|
|
89
|
+
eventHandler(() => "Hello world!"),
|
|
90
90
|
);
|
|
91
91
|
|
|
92
92
|
createServer(toNodeListener(app)).listen(process.env.PORT || 3000);
|
|
@@ -101,7 +101,7 @@ import { listen } from "listhen";
|
|
|
101
101
|
const app = createApp();
|
|
102
102
|
app.use(
|
|
103
103
|
"/",
|
|
104
|
-
eventHandler(() => "Hello world!")
|
|
104
|
+
eventHandler(() => "Hello world!"),
|
|
105
105
|
);
|
|
106
106
|
|
|
107
107
|
listen(toNodeListener(app));
|
|
@@ -121,11 +121,11 @@ const app = createApp();
|
|
|
121
121
|
const router = createRouter()
|
|
122
122
|
.get(
|
|
123
123
|
"/",
|
|
124
|
-
eventHandler(() => "Hello World!")
|
|
124
|
+
eventHandler(() => "Hello World!"),
|
|
125
125
|
)
|
|
126
126
|
.get(
|
|
127
127
|
"/hello/:name",
|
|
128
|
-
eventHandler((event) => `Hello ${event.context.params.name}!`)
|
|
128
|
+
eventHandler((event) => `Hello ${event.context.params.name}!`),
|
|
129
129
|
);
|
|
130
130
|
|
|
131
131
|
app.use(router);
|
|
@@ -143,14 +143,14 @@ For using nested routers, see [this example](https://stackblitz.com/edit/github-
|
|
|
143
143
|
// Handle can directly return object or Promise<object> for JSON response
|
|
144
144
|
app.use(
|
|
145
145
|
"/api",
|
|
146
|
-
eventHandler((event) => ({ url: event.node.req.url }))
|
|
146
|
+
eventHandler((event) => ({ url: event.node.req.url })),
|
|
147
147
|
);
|
|
148
148
|
|
|
149
149
|
// We can have better matching other than quick prefix match
|
|
150
150
|
app.use(
|
|
151
151
|
"/odd",
|
|
152
152
|
eventHandler(() => "Is odd!"),
|
|
153
|
-
{ match: (url) => url.substr(1) % 2 }
|
|
153
|
+
{ match: (url) => url.substr(1) % 2 },
|
|
154
154
|
);
|
|
155
155
|
|
|
156
156
|
// Handle can directly return string for HTML response
|
|
@@ -160,11 +160,11 @@ app.use(eventHandler(() => "<h1>Hello world!</h1>"));
|
|
|
160
160
|
app
|
|
161
161
|
.use(
|
|
162
162
|
"/1",
|
|
163
|
-
eventHandler(() => "<h1>Hello world!</h1>")
|
|
163
|
+
eventHandler(() => "<h1>Hello world!</h1>"),
|
|
164
164
|
)
|
|
165
165
|
.use(
|
|
166
166
|
"/2",
|
|
167
|
-
eventHandler(() => "<h1>Goodbye!</h1>")
|
|
167
|
+
eventHandler(() => "<h1>Goodbye!</h1>"),
|
|
168
168
|
);
|
|
169
169
|
|
|
170
170
|
// We can proxy requests and rewrite cookie's domain and path
|
|
@@ -181,8 +181,8 @@ app.use(
|
|
|
181
181
|
cookiePathRewrite: {
|
|
182
182
|
"/": "/api",
|
|
183
183
|
},
|
|
184
|
-
})
|
|
185
|
-
)
|
|
184
|
+
}),
|
|
185
|
+
),
|
|
186
186
|
);
|
|
187
187
|
|
|
188
188
|
// Legacy middleware with 3rd argument are automatically promisified
|
|
@@ -190,7 +190,7 @@ app.use(
|
|
|
190
190
|
fromNodeMiddleware((req, res, next) => {
|
|
191
191
|
req.setHeader("x-foo", "bar");
|
|
192
192
|
next();
|
|
193
|
-
})
|
|
193
|
+
}),
|
|
194
194
|
);
|
|
195
195
|
|
|
196
196
|
// Lazy loaded routes using { lazy: true }
|
|
@@ -213,7 +213,7 @@ H3 has a concept of composable utilities that accept `event` (from `eventHandler
|
|
|
213
213
|
#### Request
|
|
214
214
|
|
|
215
215
|
- `getQuery(event)`
|
|
216
|
-
- `
|
|
216
|
+
- `getValidatedQuery(event, validate)`
|
|
217
217
|
- `getRouterParams(event)`
|
|
218
218
|
- `getMethod(event, default?)`
|
|
219
219
|
- `isMethod(event, expected, allowHead?)`
|
|
@@ -224,6 +224,7 @@ H3 has a concept of composable utilities that accept `event` (from `eventHandler
|
|
|
224
224
|
- `getRequestHost(event)`
|
|
225
225
|
- `getRequestProtocol(event)`
|
|
226
226
|
- `getRequestPath(event)`
|
|
227
|
+
- `getRequestIP(event, { xForwardedFor: boolean })`
|
|
227
228
|
|
|
228
229
|
#### Response
|
|
229
230
|
|
|
@@ -311,7 +312,7 @@ PRs are welcome to add your packages.
|
|
|
311
312
|
- [h3-valibot](https://github.com/intevel/h3-valibot)
|
|
312
313
|
- `useValidateBody(event, schema)`
|
|
313
314
|
- `useValidateParams(event, schema)`
|
|
314
|
-
|
|
315
|
+
|
|
315
316
|
## License
|
|
316
317
|
|
|
317
318
|
MIT
|