rsnext/examples/custom-server-hapi
2020-08-29 22:32:35 -04:00
..
pages Fixes Hapi custom server example (#15292) 2020-07-21 13:27:39 -04:00
public Fixes Hapi custom server example (#15292) 2020-07-21 13:27:39 -04:00
.gitignore Added .gitignore to examples that are deployed to vercel (#15127) 2020-07-16 10:52:23 -04:00
next-wrapper.js removed renderToHTML from ssr-caching and custom-server-hapi in examples (#16138) 2020-08-13 04:43:46 +00:00
package.json Ensure all examples are MIT licensed (#16691) 2020-08-29 22:32:35 -04:00
README.md Simplify example usage instructions (#16678) 2020-08-29 22:22:02 -04:00
server.js Fixes Hapi custom server example (#15292) 2020-07-21 13:27:39 -04:00

Custom server using Hapi 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 Hapi 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.

How to use

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

npx create-next-app --example custom-server-hapi custom-server-hapi-app
# or
yarn create next-app --example custom-server-hapi custom-server-hapi-app