Unverified Commit 59104582 authored by Insik-Han's avatar Insik-Han Committed by GitHub

update examples/custom-server-fastify and replace depreaction (#38269)



## 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: 's avatarBalázs Orbán <18369201+balazsorban44@users.noreply.github.com>
Co-authored-by: 's avatarJJ Kasper <22380829+ijjk@users.noreply.github.com>
parent 0d5a692d
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
"start": "cross-env NODE_ENV=production node ./server.js" "start": "cross-env NODE_ENV=production node ./server.js"
}, },
"dependencies": { "dependencies": {
"cross-env": "^7.0.2", "cross-env": "^7.0.3",
"fastify": "^3.19.1", "fastify": "^4.2.0",
"next": "latest", "next": "latest",
"react": "^17.0.2", "react": "^18.2.0",
"react-dom": "^17.0.2" "react-dom": "^18.2.0"
} }
} }
/** @type {import('fastify').FastifyInstance} */
const fastify = require('fastify')({ const fastify = require('fastify')({
logger: { level: 'error' }, logger: { level: 'error' },
pluginTimeout: 0, pluginTimeout: 0,
...@@ -16,32 +17,32 @@ fastify.register((fastify, opts, next) => { ...@@ -16,32 +17,32 @@ fastify.register((fastify, opts, next) => {
if (dev) { if (dev) {
fastify.get('/_next/*', (req, reply) => { fastify.get('/_next/*', (req, reply) => {
return handle(req.raw, reply.raw).then(() => { return handle(req.raw, reply.raw).then(() => {
reply.sent = true reply.hijack()
}) })
}) })
} }
fastify.get('/a', (req, reply) => { fastify.get('/a', (req, reply) => {
return app.render(req.raw, reply.raw, '/a', req.query).then(() => { return app.render(req.raw, reply.raw, '/a', req.query).then(() => {
reply.sent = true reply.hijack()
}) })
}) })
fastify.get('/b', (req, reply) => { fastify.get('/b', (req, reply) => {
return app.render(req.raw, reply.raw, '/b', req.query).then(() => { return app.render(req.raw, reply.raw, '/b', req.query).then(() => {
reply.sent = true reply.hijack()
}) })
}) })
fastify.all('/*', (req, reply) => { fastify.all('/*', (req, reply) => {
return handle(req.raw, reply.raw).then(() => { return handle(req.raw, reply.raw).then(() => {
reply.sent = true reply.hijack()
}) })
}) })
fastify.setNotFoundHandler((request, reply) => { fastify.setNotFoundHandler((request, reply) => {
return app.render404(request.raw, reply.raw).then(() => { return app.render404(request.raw, reply.raw).then(() => {
reply.sent = true reply.hijack()
}) })
}) })
...@@ -50,7 +51,7 @@ fastify.register((fastify, opts, next) => { ...@@ -50,7 +51,7 @@ fastify.register((fastify, opts, next) => {
.catch((err) => next(err)) .catch((err) => next(err))
}) })
fastify.listen(port, (err) => { fastify.listen({ port }, (err) => {
if (err) throw err if (err) throw err
console.log(`> Ready on http://localhost:${port}`) console.log(`> Ready on http://localhost:${port}`)
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment