1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/examples/with-zones
James Hegedus b1d8b839dd Examples: use npx and yarn create to run create-next-app on examples (#4002)
* remove global npm install of create-next-app

* add npx to create-next-app command in examples

* add bash to shell snippets

* add yarn create to next-app command in examples

* fix READMEs named with lowercase

* change READMEs to use UPPERCASE
2018-03-14 09:09:46 +01:00
..
blog Use latest instead of zones for with-zones example (#3710) 2018-02-06 10:09:01 -05:00
home Update Next.js version on examples 2018-01-30 21:46:15 +01:00
package.json Update Next.js version on examples 2018-01-30 21:46:15 +01:00
README.md Examples: use npx and yarn create to run create-next-app on examples (#4002) 2018-03-14 09:09:46 +01:00
rules-dev.json Universal Webpack (#3578) 2018-01-30 16:44:44 +01:00
rules-prod.json Universal Webpack (#3578) 2018-01-30 16:44:44 +01:00

Deploy to now

Using multiple zones

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 also have a set of rules defined in rules.json for the proxy.

Now let's start two of our app using:

npm run home
npm run blog

Then start the proxy:

npm run proxy

Now you can visit http://localhost:9000 and access and develop both apps a single app.

Proxy Rules

This is the place we define rules for our proxy. Here are the rules(in rules.json) available for this app:

{
  "rules": [
    {"pathname": "/blog", "method":["GET", "POST", "OPTIONS"], "dest": "http://localhost:5000"},
    {"pathname": "/**", "dest": "http://localhost:4000"}
  ]
}

These rules are based on ZEIT now path alias rules and use micro-proxy as the proxy.

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 behaviour in client side navigation.
    • According to the above example, a page named blog should not be exist in the home zone.

Production Deployment

Here's how are going to deploy this application into production.

  • Open the now.json file in both blog and home directories and change the aliases as you wish.
  • Then update rules-prod.json accordingly.
  • Now deploy both apps:
cd home
now && now alias
cd ../blog
now && now alias
cd ..
  • Finally, set the path alias rules with
now alias with-zones.now.sh -r rules-prod.json

You can use a domain name of your choice in the above command instead of with-zones.now.sh.

That's it. Now you can access the final app via: https://with-zones.now.sh