Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/1.guide/1.basics/3.middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ app.use(

app.use(
onResponse((response, event) => {
console.log(`[${event.req.method}] ${event.url.pathname} ~>`, body);
console.log(`[${event.req.method}] ${event.url.pathname} ~>`, response.status);
}),
);

Expand Down
6 changes: 3 additions & 3 deletions docs/1.guide/1.basics/4.handler.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,16 @@ import { H3, fromWebHandler } from "h3";

export const app = new H3();

const webHandler = (request) => new Response("👋 Hello!"));
const webHandler = (request) => new Response("👋 Hello!");

// Using fromWebHandler utiliy
app.all("/web", fromWebHandler(webHandler));

// Using simple wrapper
app.all("/web", event => webHandler(event.req));
app.all("/web", (event) => webHandler(event.req));

// Using app.mount
app.mount("/web", webHandler)
app.mount("/web", webHandler);
```

### From Node.js Handlers
Expand Down
2 changes: 1 addition & 1 deletion docs/1.guide/1.basics/5.response.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ You can also use `html` utility as shortcut.
```js
import { html } from "h3";

app.get("/", (event) => html(event, "<h1>hello world</h1>"));
app.get("/", () => html("<h1>hello world</h1>"));
```

### `Response`
Expand Down
2 changes: 1 addition & 1 deletion docs/1.guide/1.basics/6.error.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ import { onError } from "h3";

// Handling errors using middleware
app.use(
onError(event, (event, error) => {
onError((error, event) => {
console.error(error);
}),
);
Expand Down
2 changes: 1 addition & 1 deletion docs/1.guide/900.api/1.h3.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const app = new H3({
console.log("Request:", event.req.url);
},
onResponse: (response, event) => {
console.log("Response:", event.path, response.status);
console.log("Response:", event.url.pathname, response.status);
},
onError: (error, event) => {
console.error(error);
Expand Down
6 changes: 3 additions & 3 deletions docs/2.utils/2.response.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ return iterable(async function* work() {
// Open document body
yield "<!DOCTYPE html>\n<html><body><h1>Executing...</h1><ol>\n";
// Do work ...
for (let i = 0; i < 1000) {
for (let i = 0; i < 1000; i++) {
await delay(1000);
// Report progress
yield `<li>Completed job #`;
Expand All @@ -96,9 +96,9 @@ return iterable(async function* work() {
}
// Close out the report
return `</ol></body></html>`;
})
});
async function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
return new Promise((resolve) => setTimeout(resolve, ms));
}
```

Expand Down
6 changes: 3 additions & 3 deletions src/utils/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function writeEarlyHints(
* // Open document body
* yield "<!DOCTYPE html>\n<html><body><h1>Executing...</h1><ol>\n";
* // Do work ...
* for (let i = 0; i < 1000) {
* for (let i = 0; i < 1000; i++) {
* await delay(1000);
* // Report progress
* yield `<li>Completed job #`;
Expand All @@ -114,9 +114,9 @@ export function writeEarlyHints(
* }
* // Close out the report
* return `</ol></body></html>`;
* })
* });
* async function delay(ms) {
* return new Promise(resolve => setTimeout(resolve, ms));
* return new Promise((resolve) => setTimeout(resolve, ms));
* }
*/
export function iterable<Value = unknown, Return = unknown>(
Expand Down
Loading