Commit 89ad01ca authored by JJ Kasper's avatar JJ Kasper Committed by Tim Neutkens

Update with-zones example to support Now v2 / serverless (#6485)

Fixes: #6468 
parent e52508fb
......@@ -68,7 +68,6 @@ This is the place we define rules for our proxy. Here are the rules(in `rules.js
"rules": [
{
"pathname": "/blog",
"method": ["GET", "POST", "OPTIONS"],
"dest": "http://localhost:5000"
},
{ "pathname": "/**", "dest": "http://localhost:4000" }
......@@ -76,7 +75,7 @@ This is the place we define rules for our proxy. Here are the rules(in `rules.js
}
```
These rules are based on ZEIT now [path alias](https://zeit.co/docs/features/path-aliases) rules and use [`micro-proxy`](https://github.com/zeit/micro-proxy) as the proxy.
These rules are based on ZEIT now v1 [path alias](https://zeit.co/docs/features/path-aliases) rules and use [`micro-proxy`](https://github.com/zeit/micro-proxy) as the proxy.
## Special Notes
......@@ -87,8 +86,8 @@ These rules are based on ZEIT now [path alias](https://zeit.co/docs/features/pat
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.
* Open the `now.json` and `next.config.js` files in both `blog` and `home` directories and change the aliases as you wish.
* Then update `routes` in `home/now.json` accordingly.
* Now deploy both apps:
```bash
......@@ -99,13 +98,7 @@ now && now alias
cd ..
```
* Finally, set the path alias rules with
```bash
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`.
> You can use a domain name of your choice in the above command instead of `with-zones.nextjs.org`.
That's it.
Now you can access the final app via: <https://with-zones.now.sh>
Now you can access the final app via: <https://with-zones.nextjs.org>
const { NOW_URL } = process.env
const { alias } = require('./now.json')
const { DEPLOY } = process.env
const alias = 'with-zones-blog.nextjs.org'
module.exports = {
assetPrefix: NOW_URL ? `https://${alias}` : 'http://localhost:5000'
target: 'serverless',
assetPrefix: DEPLOY ? `https://${alias}` : 'http://localhost:5000'
}
{
"alias": "with-zones-blog.now.sh"
}
"version": 2,
"name": "with-zones-blog",
"alias": "with-zones-blog.nextjs.org",
"build": {
"env": {
"DEPLOY": "true"
}
},
"builds": [
{ "src": "package.json", "use": "@now/next" }
]
}
\ No newline at end of file
export default () => <div>This is our blog</div>
export default () => (
<div>
<h3>This is our blog</h3>
<a href='/'>Go Back</a>
</div>
)
const { NOW_URL } = process.env
const { alias } = require('./now.json')
const { DEPLOY } = process.env
const alias = 'with-zones.nextjs.org'
module.exports = {
assetPrefix: NOW_URL ? `https://${alias}` : 'http://localhost:4000'
target: 'serverless',
assetPrefix: DEPLOY ? `https://${alias}` : 'http://localhost:4000'
}
{
"alias": "with-zones-home.now.sh"
}
"version": 2,
"name": "with-zones-home",
"alias": "with-zones.nextjs.org",
"build": {
"env": {
"DEPLOY": "true"
}
},
"builds": [
{ "src": "package.json", "use": "@now/next" }
],
"routes": [
{ "src": "/blog", "dest": "https://with-zones-blog.nextjs.org" }
]
}
\ No newline at end of file
......@@ -8,9 +8,7 @@ export default () => (
<Header />
<p>This is our homepage</p>
<div>
<Link href='/blog'>
<a>Blog</a>
</Link>
<a href='/blog'>Blog</a>
</div>
<div>
<Link href='/about'>
......
......@@ -2,17 +2,17 @@
"name": "with-zones",
"version": "1.0.0",
"scripts": {
"home": "next home -p 4000",
"home": "cd home && next dev -p 4000",
"home-build": "next build home",
"home-start": "next start home -p 4000",
"blog": "next blog -p 5000",
"blog": "cd blog && next dev -p 5000",
"blog-build": "next build blog",
"blog-start": "next start blog -p 5000",
"proxy": "micro-proxy -r rules-dev.json"
},
"dependencies": {
"micro-proxy": "^1.0.0",
"next": "5.0.0-universal-alpha.15",
"next": "latest",
"react": "^16.7.0",
"react-dom": "^16.7.0"
},
......
{
"rules": [
{"pathname": "/blog", "method":["GET", "POST", "OPTIONS"], "dest": "http://localhost:5000"},
{"pathname": "/blog", "dest": "http://localhost:5000"},
{"pathname": "/**", "dest": "http://localhost:4000"}
]
}
{
"rules": [
{"pathname": "/blog", "method":["GET", "POST", "OPTIONS"], "dest": "https://with-zones-blog.now.sh"},
{"pathname": "/**", "dest": "https://with-zones-home.now.sh"}
]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment