Skip to content

Commit

Permalink
update examples/custom-server-fastify and replace depreaction (#38269)
Browse files Browse the repository at this point in the history
## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [x] Make sure the linting passes by running `pnpm lint`
- [x] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)


Co-authored-by: Balázs Orbán <18369201+balazsorban44@users.noreply.github.com>
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
  • Loading branch information
3 people committed Aug 7, 2022
1 parent 0d5a692 commit 5910458
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
8 changes: 4 additions & 4 deletions examples/custom-server-fastify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"start": "cross-env NODE_ENV=production node ./server.js"
},
"dependencies": {
"cross-env": "^7.0.2",
"fastify": "^3.19.1",
"cross-env": "^7.0.3",
"fastify": "^4.2.0",
"next": "latest",
"react": "^17.0.2",
"react-dom": "^17.0.2"
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
}
13 changes: 7 additions & 6 deletions examples/custom-server-fastify/server.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('fastify').FastifyInstance} */
const fastify = require('fastify')({
logger: { level: 'error' },
pluginTimeout: 0,
Expand All @@ -16,32 +17,32 @@ fastify.register((fastify, opts, next) => {
if (dev) {
fastify.get('/_next/*', (req, reply) => {
return handle(req.raw, reply.raw).then(() => {
reply.sent = true
reply.hijack()
})
})
}

fastify.get('/a', (req, reply) => {
return app.render(req.raw, reply.raw, '/a', req.query).then(() => {
reply.sent = true
reply.hijack()
})
})

fastify.get('/b', (req, reply) => {
return app.render(req.raw, reply.raw, '/b', req.query).then(() => {
reply.sent = true
reply.hijack()
})
})

fastify.all('/*', (req, reply) => {
return handle(req.raw, reply.raw).then(() => {
reply.sent = true
reply.hijack()
})
})

fastify.setNotFoundHandler((request, reply) => {
return app.render404(request.raw, reply.raw).then(() => {
reply.sent = true
reply.hijack()
})
})

Expand All @@ -50,7 +51,7 @@ fastify.register((fastify, opts, next) => {
.catch((err) => next(err))
})

fastify.listen(port, (err) => {
fastify.listen({ port }, (err) => {
if (err) throw err
console.log(`> Ready on http://localhost:${port}`)
})

0 comments on commit 5910458

Please sign in to comment.