Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit f73be2d

Browse files
committed
update fastify
1 parent 0faeaa7 commit f73be2d

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

docs/guides/nodejs/fastify.mdx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,21 @@ fastify.get('/', (request, reply) => {
6868
reply.send('Hello World!')
6969
})
7070

71-
http(fastify)
71+
async function bootstrap(port: number) {
72+
const address = await fastify.listen({ port })
73+
74+
console.log(`Server listening on ${address}`)
75+
76+
return fastify.server
77+
}
78+
79+
http(bootstrap)
7280
```
7381

7482
<Note>
75-
If you're familiar with Fastify you'll notice this example doesn't call
76-
`fastify.listen`. The Nitric `http` function takes care of that, as well as
77-
binding the application to the correct port in each environment.
83+
The `http` function is a Nitric helper that allows you to bootstrap your
84+
Fastify application with Nitric. Here we're passing the port number as an
85+
argument to the `fastify.listen` function and returning the server instance.
7886
</Note>
7987

8088
At this point we're ready to start testing locally.
@@ -111,14 +119,14 @@ fastify.get('/', async (request, reply) => {
111119
})
112120

113121
async function bootstrap(port: number) {
114-
await fastify.listen({ port })
122+
const address = await fastify.listen({ port })
123+
124+
console.log(`Server listening on ${address}`)
115125

116126
return fastify.server
117127
}
118128

119-
http(bootstrap, () => {
120-
console.log(`Application started`)
121-
})
129+
http(bootstrap)
122130
```
123131

124132
We'll also add a new function to do the background work:

0 commit comments

Comments
 (0)