|
2 | 2 |
|
3 | 3 | With Next.js you can use multiple apps as a single app using it's [multi-zones feature](https://nextjs.org/docs#multi-zones). This is an example showing how to use it.
|
4 | 4 |
|
| 5 | +- All pages should be unique across zones. For example, the `home` app should not have a `pages/blog/index.js` page. |
| 6 | +- The `blog` app sets `assetPrefix` so that generated JS bundles are within the `/blog` subfolder. |
| 7 | + - To also support the plain `next dev` scenario, `assetPrefix` is set dynamically based on the `BUILDING_FOR_NOW` environment variable, see [`now.json`](now.json) and [`blog/next.config.js`](blog/next.config.js). |
| 8 | + - Images and other `/static` assets have to be prefixed manually, e.g., `` <img src={`${process.env.ASSET_PREFIX}/static/image.png`} /> ``, see [`blog/pages/blog/index.js`](blog/pages/blog/index.js). |
| 9 | + |
5 | 10 | ## Deploy your own
|
6 | 11 |
|
7 | 12 | Deploy the example using [ZEIT Now](https://zeit.co/now):
|
@@ -29,31 +34,16 @@ curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2
|
29 | 34 | cd with-zones
|
30 | 35 | ```
|
31 | 36 |
|
32 |
| -## Notes |
33 |
| - |
34 |
| -In this example, we have two apps: 'home' and 'blog'. You can start each app separately, for example: |
| 37 | +For every app, install dependencies and run the dev server: |
35 | 38 |
|
36 | 39 | ```bash
|
37 |
| -cd blog |
| 40 | +npm install |
| 41 | +npm run dev |
| 42 | +# or |
| 43 | +yarn |
38 | 44 | yarn dev
|
39 | 45 | ```
|
40 | 46 |
|
41 |
| -Then, you can visit <http://localhost:3000> and develop your app. |
42 |
| - |
43 |
| -## Special Notes |
44 |
| - |
45 |
| -- All pages should be unique across zones. For example, the 'home' app should not have a `pages/blog/index.js` page. |
46 |
| -- The 'blog' app sets `assetPrefix` so that generated JS bundles are within the `/blog` subfolder. |
47 |
| - - To also support the plain `next dev` scenario, `assetPrefix` is set dynamically based on the `BUILDING_FOR_NOW` environment variable, see [`now.json`](now.json) and [`blog/next.config.js`](blog/next.config.js). |
48 |
| - - Images and other `/static` assets have to be prefixed manually, e.g., `` <img src={`${process.env.ASSET_PREFIX}/static/image.png`} /> ``, see [`blog/pages/blog/index.js`](blog/pages/blog/index.js). |
49 |
| - |
50 |
| -## Production Deployment |
51 |
| - |
52 |
| -We only need to run `now <app>`, to deploy the app: |
53 |
| - |
54 |
| -```bash |
55 |
| -now blog |
56 |
| -now home |
57 |
| -``` |
| 47 | +The `home` app will start in the default port (http://localhost:3000), and `blog` will start on http://localhost:4000. |
58 | 48 |
|
59 |
| -> The rewrite destination in your `now.json` file in the `home` app must be adjusted to point to your deployment. |
| 49 | +Deploy it to the cloud with [ZEIT Now](https://zeit.co/import?filter=next.js&utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)). |
0 commit comments