Skip to content

Commit 6c1c681

Browse files
authored
docs(nuxt): Use H3 utilities (#257)
Just a small PR replacing direct response manipulation with H3's utils 🫡 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Standardized error handling for unmatched routes by implementing a unified approach for setting response statuses. - Improved header management by adopting a consistent method for retrieving authorization details. - Adjusted the flow for HTML responses to return content directly instead of explicitly ending responses. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent f4d410a commit 6c1c681

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

apps/content/docs/integrations/nuxt.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export default defineEventHandler(async (event) => {
3030
return
3131
}
3232

33-
event.node.res.statusCode = 404
34-
event.node.res.end('Not found')
33+
setResponseStatus(event, 404, 'Not Found')
34+
return 'Not found'
3535
})
3636
```
3737

playgrounds/nuxt/server/routes/api/[...].ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ const openAPIHandler = new OpenAPIHandler(router, {
1515
})
1616

1717
export default defineEventHandler(async (event) => {
18-
const context = event.node.req.headers.authorization
18+
const authorization = getHeader(event, 'authorization')
19+
const context = authorization
1920
? { user: { id: 'test', name: 'John Doe', email: 'john@doe.com' } }
2021
: {}
2122

@@ -28,6 +29,6 @@ export default defineEventHandler(async (event) => {
2829
return
2930
}
3031

31-
event.node.res.statusCode = 404
32-
event.node.res.end('Not found')
32+
setResponseStatus(event, 404, 'Not Found')
33+
return 'Not Found'
3334
})

playgrounds/nuxt/server/routes/rpc/[...].ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const rpcHandler = new RPCHandler(router, {
1111
})
1212

1313
export default defineEventHandler(async (event) => {
14-
const context = event.node.req.headers.authorization
14+
const authorization = getHeader(event, 'authorization')
15+
const context = authorization
1516
? { user: { id: 'test', name: 'John Doe', email: 'john@doe.com' } }
1617
: {}
1718

@@ -24,6 +25,6 @@ export default defineEventHandler(async (event) => {
2425
return
2526
}
2627

27-
event.node.res.statusCode = 404
28-
event.node.res.end('Not found')
28+
setResponseStatus(event, 404, 'Not Found')
29+
return 'Not Found'
2930
})

playgrounds/nuxt/server/routes/scalar.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ export default defineEventHandler(async (event) => {
3232
</html>
3333
`
3434

35-
event.node.res.setHeader('Content-Type', 'text/html')
36-
event.node.res.end(html)
35+
setResponseHeader(event, 'content-type', 'text/html')
36+
return html
3737
})

0 commit comments

Comments
 (0)