rsnext/examples/with-zones
Borek Bernard 233152ee17 Add package.json to with-zones example, make create-next-app work (#8453)
* Add package.json to with-zones example

So that create-next-app works.

* Update README – no need to run `yarn` / `npm i`

This example doesn't have any dependencies in its package.json,
everything is handled by running `now dev`.
2019-08-20 14:45:16 -04:00
..
blog Update with-zones example and Multi Zones documentation (#7513) 2019-07-01 15:21:00 -07:00
home Update with-zones example and Multi Zones documentation (#7513) 2019-07-01 15:21:00 -07:00
now.json Update with-zones example and Multi Zones documentation (#7513) 2019-07-01 15:21:00 -07:00
package.json Add package.json to with-zones example, make create-next-app work (#8453) 2019-08-20 14:45:16 -04:00
README.md Add package.json to with-zones example, make create-next-app work (#8453) 2019-08-20 14:45:16 -04:00

Using multiple zones

How to use

Using create-next-app

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

npx create-next-app --example with-zones with-zones-app
# or
yarn create next-app --example with-zones with-zones-app

Download manually

Download the example:

curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-zones
cd with-zones

The idea behind this example

With Next.js you can use multiple apps as a single app using it's multi-zones feature. This is an example showing how to use it.

In this example, we've two apps: 'home' and 'blog'. We'll start both apps with Now: We also have a set of builders and routes defined in now.json.

now dev

Now you can visit http://localhost:3000 and develop for both apps as a single app.

Now config

now.json allows us to create a single dev server for any builders and routes we add to it, with now dev we can easily create a dev server for multiple apps without having to deploy or setup anything else:

{
  "name": "with-zones",
  "version": 2,
  "builds": [
    { "src": "blog/next.config.js", "use": "@now/next" },
    { "src": "home/next.config.js", "use": "@now/next" }
  ],
  "routes": [
    { "src": "/blog/_next(.*)", "dest": "blog/_next$1" },
    { "src": "/blog", "dest": "blog/blog" },
    { "src": "(.*)", "dest": "home$1" }
  ]
}

The previous file is based in the @now/next builder and Now Routes from Now V2.

Special Notes

  • All pages should be unique across zones. A page with the same name should not exist in multiple zones. Otherwise, there'll be unexpected behaviours in client side navigation.
    • According to the above example, a page named blog should not be exist in the home zone.

Production Deployment

We only need to run now, the same now.json used for development will be used for the deployment:

now