Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 9 commits into from Aug 7, 2022
10 changes: 6 additions & 4 deletions examples/custom-server-fastify/package.json
Expand Up @@ -6,10 +6,12 @@
"start": "cross-env NODE_ENV=production node ./server.js"
},
"dependencies": {
"cross-env": "^7.0.2",
"fastify": "^3.19.1",
"fastify": "^4.2.0",
"next": "latest",
"react": "^17.0.2",
"react-dom": "^17.0.2"
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"cross-env": "^7.0.3"
ijjk marked this conversation as resolved.
Show resolved Hide resolved
}
}
13 changes: 7 additions & 6 deletions examples/custom-server-fastify/server.js
@@ -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}`)
})