rsnext/examples/custom-server-fastify
Insik-Han 5910458245
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: Balázs Orbán <18369201+balazsorban44@users.noreply.github.com>
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-08-07 16:52:02 +00:00
..
pages chore: remove-redundant-example-import (#13175) 2020-05-22 16:13:37 +00:00
.gitignore Update default gitignore templates (#39051) 2022-07-26 20:08:40 -05:00
package.json update examples/custom-server-fastify and replace depreaction (#38269) 2022-08-07 16:52:02 +00:00
README.md docs(examples): improve DX while copying command to create new project (#38410) 2022-07-26 21:57:48 -05:00
server.js update examples/custom-server-fastify and replace depreaction (#38269) 2022-08-07 16:52:02 +00:00

Custom Fastify Server example

Most of the times the default Next server will be enough but sometimes you want to run your own server to customize routes or other kind of the app behavior. Next provides a Custom server and routing so you can customize as much as you want.

Because the Next.js server is just a node.js module you can combine it with any other part of the node.js ecosystem. in this case we are using Fastify to build a custom router on top of Next.

The example shows a server that serves the component living in pages/a.js when the route /b is requested and pages/b.js when the route /a is accessed. This is obviously a non-standard routing strategy. You can see how this custom routing is being made inside server.js.

Deploy your own

Deploy the example using Vercel or preview live with StackBlitz

Deploy with Vercel

How to use

Execute create-next-app with npm, Yarn, or pnpm to bootstrap the example:

npx create-next-app --example custom-server-fastify custom-server-fastify-app
yarn create next-app --example custom-server-fastify custom-server-fastify-app
pnpm create next-app --example custom-server-fastify custom-server-fastify-app