Commit dc06fee7 authored by Arunoda Susiripala's avatar Arunoda Susiripala

Merge branch 'canary' into multi-zones

parents a72eb3e2 5daafa4f
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
language: "node_js", language: "node_js",
node_js: ["6"], node_js: ["6"],
cache: { cache: {
directories: ["node-modules"] directories: ["node_modules"]
}, },
before_install: [ before_install: [
"rm yarn.lock", "rm yarn.lock",
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
deploy: { deploy: {
provider: "npm", provider: "npm",
email: "leo@zeit.co", email: "leo@zeit.co",
tag: "canary",
api_key: { api_key: {
secure: secure:
"br9gLncKeLSoL7iOq0PXFeD1Gp3jRI8QMCSNIrGdZg/MuLeuwYPv36kmMgf7aGIfpjFLtU2/eVrOHSB+T5g1nKgOsqmWsfZE1tQYWph0//ookd/sj+IyxIx8nVLbUV/C4ctYOhX/efotRgNn56w5Av5hWc1IQLmW9mSN8ijrQnM+GzRI8QitiofeY2EP3N1eO8vC8E2oGkOsAdcypiX6lFG908zyWt7X2SD+iOsK2eAHjxoAEUdrxE5a8gTDhcTH6qnmtBs9rCeEKbO3JZjEy5dvccxlX3Nd+2GC1rckayk6o5L/zveTilsUx6Auqqbwn1dT5ffQuYsV4RPofs8IMrhnizc8y+OfUcCCpBJ4ia4w7N8FEP56TnRNTFoFBGJL5Y6NfeT0HHAlClxUWMG9pRGWGN+sskODDQ9FEntGZoqwV396ogs+3YhkxbY0AIr84QOctflsFcPtOgr/CoBeOsjbB+o9+Rlsqwlf3u3B7qhtU9eV6KcMfK4x9qW+2cwTllK+gD8S9wILx5BChkfx99g/7u/Rg1PCym64tTsDOBtqTVC2YCqeYYvjmpw4Vl3ofLrFsoNQnbmb6Q5+JSpOcJ/bEj7P/FuZdlU0fNV28tFhElu5caKhSCJz/avUlXG7NeveW1Ee8gjhURC4V/l4ryacyjA2vcDY/4RRkWtHNr4=" "br9gLncKeLSoL7iOq0PXFeD1Gp3jRI8QMCSNIrGdZg/MuLeuwYPv36kmMgf7aGIfpjFLtU2/eVrOHSB+T5g1nKgOsqmWsfZE1tQYWph0//ookd/sj+IyxIx8nVLbUV/C4ctYOhX/efotRgNn56w5Av5hWc1IQLmW9mSN8ijrQnM+GzRI8QitiofeY2EP3N1eO8vC8E2oGkOsAdcypiX6lFG908zyWt7X2SD+iOsK2eAHjxoAEUdrxE5a8gTDhcTH6qnmtBs9rCeEKbO3JZjEy5dvccxlX3Nd+2GC1rckayk6o5L/zveTilsUx6Auqqbwn1dT5ffQuYsV4RPofs8IMrhnizc8y+OfUcCCpBJ4ia4w7N8FEP56TnRNTFoFBGJL5Y6NfeT0HHAlClxUWMG9pRGWGN+sskODDQ9FEntGZoqwV396ogs+3YhkxbY0AIr84QOctflsFcPtOgr/CoBeOsjbB+o9+Rlsqwlf3u3B7qhtU9eV6KcMfK4x9qW+2cwTllK+gD8S9wILx5BChkfx99g/7u/Rg1PCym64tTsDOBtqTVC2YCqeYYvjmpw4Vl3ofLrFsoNQnbmb6Q5+JSpOcJ/bEj7P/FuZdlU0fNV28tFhElu5caKhSCJz/avUlXG7NeveW1Ee8gjhURC4V/l4ryacyjA2vcDY/4RRkWtHNr4="
......
...@@ -27,13 +27,18 @@ const commands = new Set([ ...@@ -27,13 +27,18 @@ const commands = new Set([
]) ])
let cmd = process.argv[2] let cmd = process.argv[2]
let args let args = []
let nodeArgs = []
if (new Set(['--version', '-v']).has(cmd)) { if (new Set(['--version', '-v']).has(cmd)) {
console.log(`next.js v${pkg.version}`) console.log(`next.js v${pkg.version}`)
process.exit(0) process.exit(0)
} }
if (new Set(process.argv).has('--inspect')) {
nodeArgs.push('--inspect')
}
if (new Set(['--help', '-h']).has(cmd)) { if (new Set(['--help', '-h']).has(cmd)) {
console.log(` console.log(`
Usage Usage
...@@ -61,7 +66,7 @@ process.env.NODE_ENV = process.env.NODE_ENV || defaultEnv ...@@ -61,7 +66,7 @@ process.env.NODE_ENV = process.env.NODE_ENV || defaultEnv
const bin = join(__dirname, 'next-' + cmd) const bin = join(__dirname, 'next-' + cmd)
const startProcess = () => { const startProcess = () => {
const proc = spawn(bin, args, { stdio: 'inherit', customFds: [0, 1, 2] }) const proc = spawn('node', [...nodeArgs, ...[bin], ...args], { stdio: 'inherit', customFds: [0, 1, 2] })
proc.on('close', (code, signal) => { proc.on('close', (code, signal) => {
if (code !== null) { if (code !== null) {
process.exit(code) process.exit(code)
......
# Build directory not writeable
#### Why This Error Occurred
The filesystem does not allow writing to the specified directory. A common cause for this error is starting a [custom server](https://github.com/zeit/next.js#custom-server-and-routing) in development mode on a production server, for example, [now.sh](https://zeit.co) which [doesn't allow you to write to the filesystem after your app is built](https://zeit.co/docs/deployment-types/node#file-system-specifications).
#### Possible Ways to Fix It
When using a custom server with a server file, for example called `server.js`, make sure you update the scripts key in `package.json` to:
```json
{
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "NODE_ENV=production node server.js"
}
}
```
and the custom server starts Next in production mode when `NODE_ENV` is `production`
```js
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
```
### Useful Links
- [Custom Server documentation + examples](https://github.com/zeit/next.js#custom-server-and-routing)
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/active-class-name)
# activeClassName example
## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example active-class-name active-class-name-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash
curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/active-class-name
cd active-class-name
```
Install it and run:
```bash
npm install
npm run dev
```
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))
```bash
now
```
## The idea behind the example
ReactRouter has a convenience property on the `Link` element to allow an author to set the _active_ className on a link. This example replicates that functionality using Next's own `Link`.
import { withRouter } from 'next/router'
import Link from 'next/link'
import React, { Children } from 'react'
const ActiveLink = ({ router, children, ...props }) => {
const child = Children.only(children)
let className = child.props.className || ''
if (router.pathname === props.href && props.activeClassName) {
className = `${className} ${props.activeClassName}`.trim()
}
delete props.activeClassName
return <Link {...props}>{React.cloneElement(child, { className })}</Link>
}
export default withRouter(ActiveLink)
import Link from './Link'
export default () => (
<nav>
<style jsx>{`
.active:after {
content: ' (current page)';
}
.nav-link {
text-decoration: none;
padding: 10px;
display: block;
}
`}</style>
<ul>
<li>
<Link activeClassName='active' href='/'>
<a className='nav-link home-link'>Home</a>
</Link>
</li>
<li>
<Link activeClassName='active' href='/about'>
<a className='nav-link'>About</a>
</Link>
</li>
</ul>
</nav>
)
{
"name": "active-class-name",
"version": "1.0.0",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"author": "Remy Sharp <remy@leftlogic.com>",
"dependencies": {
"next": "latest",
"react": "^16.0.0",
"react-dom": "^16.0.0"
},
"license": "ISC"
}
import Nav from '../components/Nav'
export default () => (
<div>
<Nav />
<p>Hello, I'm About.js</p>
</div>
)
import Nav from '../components/Nav'
export default () => (
<div>
<Nav />
<p>Hello, I'm the home page</p>
</div>
)
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example basic-css basic-css-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example custom-server-express custom-server-express-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -5,5 +5,6 @@ export default () => ( ...@@ -5,5 +5,6 @@ export default () => (
<ul> <ul>
<li><Link href='/b' as='/a'><a>a</a></Link></li> <li><Link href='/b' as='/a'><a>a</a></Link></li>
<li><Link href='/a' as='/b'><a>b</a></Link></li> <li><Link href='/a' as='/b'><a>b</a></Link></li>
<li><Link href='/posts/2'><a>post #2</a></Link></li>
</ul> </ul>
) )
import React, { Component } from 'react'
export default class extends Component {
static getInitialProps ({ query: { id } }) {
return { postId: id }
}
render () {
return <div>
<h1>My blog post #{this.props.postId}</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</p>
</div>
}
}
...@@ -18,6 +18,10 @@ app.prepare() ...@@ -18,6 +18,10 @@ app.prepare()
return app.render(req, res, '/a', req.query) return app.render(req, res, '/a', req.query)
}) })
server.get('/posts/:id', (req, res) => {
return app.render(req, res, '/posts', { id: req.params.id })
})
server.get('*', (req, res) => { server.get('*', (req, res) => {
return handle(req, res) return handle(req, res)
}) })
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example custom-server-fastify custom-server-fastify-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example custom-server-hapi custom-server-hapi-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example custom-server-koa custom-server-koa-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example custom-server-micro custom-server-micro-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/custom-server-nodemon)
# Custom server with Nodemon example
## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example custom-server-nodemon custom-server-nodemon-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash
curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/custom-server-nodemon
cd custom-server-nodemon
```
Install it and run:
```bash
npm install
npm run dev
```
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))
```bash
now
```
## The idea behind the example
The example shows how you can apply [Nodemon](https://nodemon.io/) to a custom server to have live reload of the server code without being affected by the Next.js universal code.
{
"watch": ["server/**/*.js"]
}
{
"scripts": {
"dev": "nodemon server/index.js",
"build": "next build",
"start": "NODE_ENV=production node server/index.js"
},
"dependencies": {
"next": "^4.1.4",
"react": "^16.2.0",
"react-dom": "^16.2.0"
},
"devDependencies": {
"nodemon": "^1.12.1"
}
}
import React from 'react'
export default () => <div>a</div>
import React from 'react'
export default () => <div>b</div>
import React from 'react'
import Link from 'next/link'
export default () => (
<ul>
<li><Link href='/b' as='/a'><a>a</a></Link></li>
<li><Link href='/a' as='/b'><a>b</a></Link></li>
</ul>
)
const { createServer } = require('http')
const { parse } = require('url')
const next = require('next')
const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
app.prepare()
.then(() => {
createServer((req, res) => {
const parsedUrl = parse(req.url, true)
const { pathname, query } = parsedUrl
if (pathname === '/a') {
app.render(req, res, '/b', query)
} else if (pathname === '/b') {
app.render(req, res, '/a', query)
} else {
handle(req, res, parsedUrl)
}
})
.listen(port, (err) => {
if (err) throw err
console.log(`> Ready on http://localhost:${port}`)
})
})
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example custom-server custom-server-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example data-fetch data-fetch-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
"isomorphic-fetch": "^2.2.1", "isomorphic-unfetch": "^2.0.0",
"next": "latest", "next": "latest",
"react": "^16.0.0", "react": "^16.0.0",
"react-dom": "^16.0.0" "react-dom": "^16.0.0"
......
import React from 'react' import React from 'react'
import Link from 'next/link' import Link from 'next/link'
import 'isomorphic-fetch' import 'isomorphic-unfetch'
export default class MyPage extends React.Component { export default class MyPage extends React.Component {
static async getInitialProps () { static async getInitialProps () {
......
import React from 'react' import React from 'react'
import Link from 'next/link' import Link from 'next/link'
import 'isomorphic-fetch' import 'isomorphic-unfetch'
export default class MyPage extends React.Component { export default class MyPage extends React.Component {
static async getInitialProps () { static async getInitialProps () {
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example form-handler form-handler-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example head-elements head-elements-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example hello-world hello-world-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example layout-component layout-component-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example nested-components nested-components-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
# Hello World example
## Only client render for external dependencies
Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash
curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/only-client-render-external-dependencies
cd only-client-render-external-dependencies
```
Install it and run:
```bash
npm install
npm run dev
```
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))
```bash
now
```
## The idea behind the example
This example shows how to use an external dependency that only allows client-render.
\ No newline at end of file
{
"name": "only-client-render-external-dependencies",
"version": "1.0.0",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "latest",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"recharts": "^1.0.0-beta.0"
},
"license": "ISC"
}
import React from 'react'
let LineChart
let Line
class Chart extends React.Component {
constructor () {
super()
this.state = {
chart: false,
data: [
{name: 'Page A', uv: 4000, pv: 2400, amt: 2400},
{name: 'Page B', uv: 3000, pv: 1398, amt: 2210},
{name: 'Page C', uv: 2000, pv: 9800, amt: 2290},
{name: 'Page D', uv: 2780, pv: 3908, amt: 2000},
{name: 'Page E', uv: 1890, pv: 4800, amt: 2181},
{name: 'Page F', uv: 2390, pv: 3800, amt: 2500},
{name: 'Page G', uv: 3490, pv: 4300, amt: 2100}
]
}
}
componentDidMount () {
LineChart = require('recharts').LineChart
Line = require('recharts').Line
this.setState({
chart: true
})
}
render () {
return (
<div>
<h1>Another chart</h1>
{this.state.chart &&
<LineChart width={400} height={400} data={this.state.data}>
<Line type='monotone' dataKey='uv' stroke='#8884d8' />
</LineChart>
}
</div>
)
}
}
export default Chart
import React from 'react'
import Link from 'next/link'
let LineChart
let Line
class Index extends React.Component {
constructor () {
super()
this.state = {
chart: false,
data: [
{name: 'Page A', uv: 1000, pv: 2400, amt: 2400},
{name: 'Page B', uv: 3000, pv: 1398, amt: 2210},
{name: 'Page C', uv: 2000, pv: 9800, amt: 2290},
{name: 'Page D', uv: 2780, pv: 3908, amt: 2000},
{name: 'Page E', uv: 1890, pv: 4800, amt: 2181},
{name: 'Page F', uv: 2390, pv: 3800, amt: 2500},
{name: 'Page G', uv: 3490, pv: 4300, amt: 2100}
]
}
}
componentDidMount () {
LineChart = require('recharts').LineChart
Line = require('recharts').Line
this.setState({
chart: true
})
}
render () {
return (
<div>
<h1>Chart</h1>
<Link href='/chart'><a>Go to another chart</a></Link>
{this.state.chart &&
<LineChart width={400} height={400} data={this.state.data}>
<Line type='monotone' dataKey='uv' stroke='#8884d8' />
</LineChart>
}
</div>
)
}
}
export default Index
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example page-transitions page-transitions-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example parameterized-routing parameterized-routing-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -3,6 +3,17 @@ ...@@ -3,6 +3,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example progressive-render progressive-render-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example root-static-files root-static-files-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -3,6 +3,17 @@ ...@@ -3,6 +3,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example shared-modules shared-modules-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example ssr-caching ssr-caching-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example svg-components svg-components-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example using-inferno using-inferno-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example using-preact using-preact-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -3,6 +3,17 @@ ...@@ -3,6 +3,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example using-router using-router-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -3,6 +3,17 @@ ...@@ -3,6 +3,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example using-with-router using-with-router-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -2,6 +2,17 @@ ...@@ -2,6 +2,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example with-absolute-imports with-absolute-imports-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example with-algolia-react-instantsearch with-algolia-react-instantsearch-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example with-amp with-amp-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js.git): Download the example [or clone the repo](https://github.com/zeit/next.js.git):
```bash ```bash
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example with-ant-design with-ant-design-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -3,6 +3,17 @@ ...@@ -3,6 +3,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example with-antd-mobile with-antd-mobile-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example with-aphrodite with-aphrodite-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -3,6 +3,17 @@ ...@@ -3,6 +3,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example with-apollo-and-redux with-apollo-and-redux-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -10,6 +10,10 @@ export default ({ pathname }) => ( ...@@ -10,6 +10,10 @@ export default ({ pathname }) => (
<a className={pathname === '/about' && 'is-active'}>About</a> <a className={pathname === '/about' && 'is-active'}>About</a>
</Link> </Link>
<Link prefetch href='/blog'>
<a className={pathname === '/blog' && 'is-active'}>Blog</a>
</Link>
<style jsx>{` <style jsx>{`
header { header {
margin-bottom: 25px; margin-bottom: 25px;
......
import React from 'react'
import { gql, graphql } from 'react-apollo'
import PostUpvoter from './PostUpvoter'
function Post ({ id, data: { loading, error, Post } }) {
return (
<section>
<div key={Post.id}>
<h1>{Post.title}</h1>
<p>ID: {Post.id}<br />URL: {Post.url}</p>
<PostUpvoter id={Post.id} votes={Post.votes} />
</div>
</section>
)
}
const post = gql`
query post($id: ID!) {
Post(id: $id) {
id
title
votes
url
createdAt
}
}
`
// The `graphql` wrapper executes a GraphQL query and makes the results
// available on the `data` prop of the wrapped component (PostList)
// Tip: ownProps is parent component's props
export default graphql(post, {
options: (ownProps) => {
return {
variables: {
id: ownProps.id
}
}
}
})(Post)
import { gql, graphql } from 'react-apollo' import { gql, graphql } from 'react-apollo'
import ErrorMessage from './ErrorMessage' import ErrorMessage from './ErrorMessage'
import PostUpvoter from './PostUpvoter' import PostUpvoter from './PostUpvoter'
import Link from 'next/link'
const POSTS_PER_PAGE = 10 const POSTS_PER_PAGE = 10
...@@ -15,7 +16,7 @@ function PostList ({ data: { loading, error, allPosts, _allPostsMeta }, loadMore ...@@ -15,7 +16,7 @@ function PostList ({ data: { loading, error, allPosts, _allPostsMeta }, loadMore
<li key={post.id}> <li key={post.id}>
<div> <div>
<span>{index + 1}. </span> <span>{index + 1}. </span>
<a href={post.url}>{post.title}</a> <Link href={{ pathname: '/blog/' + post.id }}><a>{post.title}</a></Link>
<PostUpvoter id={post.id} votes={post.votes} /> <PostUpvoter id={post.id} votes={post.votes} />
</div> </div>
</li> </li>
......
import { ApolloClient, createNetworkInterface } from 'react-apollo' import { ApolloClient, createNetworkInterface } from 'react-apollo'
import fetch from 'isomorphic-fetch' import fetch from 'isomorphic-unfetch'
let apolloClient = null let apolloClient = null
......
...@@ -2,14 +2,15 @@ ...@@ -2,14 +2,15 @@
"name": "with-apollo-and-redux", "name": "with-apollo-and-redux",
"version": "2.0.0", "version": "2.0.0",
"scripts": { "scripts": {
"dev": "next", "dev": "node server.js",
"build": "next build", "build": "next build",
"start": "next start" "start": "NODE_ENV=production node server.js"
}, },
"dependencies": { "dependencies": {
"graphql": "^0.9.3", "graphql": "^0.9.3",
"isomorphic-fetch": "^2.2.1", "isomorphic-unfetch": "^2.0.0",
"next": "latest", "next": "latest",
"next-routes": "^1.1.0",
"prop-types": "^15.5.8", "prop-types": "^15.5.8",
"react": "^16.0.0", "react": "^16.0.0",
"react-apollo": "^1.1.3", "react-apollo": "^1.1.3",
......
import App from '../../components/App'
import Header from '../../components/Header'
import Post from '../../components/Post'
import withData from '../../lib/withData'
export default withData((props) => (
<App>
<Header pathname={props.url.pathname} />
<Post id={props.url.query.id} />
</App>
))
import App from '../../components/App'
import Header from '../../components/Header'
import Submit from '../../components/Submit'
import PostList from '../../components/PostList'
import withData from '../../lib/withData'
export default withData((props) => (
<App>
<Header pathname={props.url.pathname} />
<Submit />
<PostList />
</App>
))
import App from '../components/App' import App from '../components/App'
import Header from '../components/Header' import Header from '../components/Header'
import Submit from '../components/Submit'
import PostList from '../components/PostList'
import withData from '../lib/withData' import withData from '../lib/withData'
export default withData((props) => ( export default withData((props) => (
<App> <App>
<Header pathname={props.url.pathname} /> <Header pathname={props.url.pathname} />
<Submit /> <h1>Welcome Home.</h1>
<PostList />
</App> </App>
)) ))
/**
* server.js
*
* You can use the default server.js by simply running `next`,
* but a custom one is required to do paramaterized urls like
* blog/:slug.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BENEVOLENT WEB LLC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
const {createServer} = require('http')
const next = require('next')
const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({dev})
/**
* Parameterized Routing with next-route
*
* Benefits: Less code, and easily handles complex url structures
*/
const routes = require('next-routes')()
routes.add('blog/entry', '/blog/:id')
const handler = routes.getRequestHandler(app)
app.prepare().then(() => {
createServer(handler)
.listen(port, (err) => {
if (err) throw err
console.log(`> Ready on http://localhost:${port}`)
})
})
...@@ -7,6 +7,17 @@ https://next-with-apollo-auth.now.sh ...@@ -7,6 +7,17 @@ https://next-with-apollo-auth.now.sh
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example with-apollo-auth with-apollo-auth-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
import { ApolloClient, createNetworkInterface } from 'react-apollo' import { ApolloClient } from 'apollo-client'
import fetch from 'isomorphic-fetch' import { createHttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { setContext } from 'apollo-link-context'
import fetch from 'isomorphic-unfetch'
let apolloClient = null let apolloClient = null
...@@ -9,25 +12,26 @@ if (!process.browser) { ...@@ -9,25 +12,26 @@ if (!process.browser) {
} }
function create (initialState, { getToken }) { function create (initialState, { getToken }) {
const networkInterface = createNetworkInterface({ const httpLink = createHttpLink({
uri: 'https://api.graph.cool/simple/v1/cj3h80ffbllm20162alevpcby' uri: 'https://api.graph.cool/simple/v1/cj5geu3slxl7t0127y8sity9r',
credentials: 'same-origin'
}) })
networkInterface.use([{ const authLink = setContext((_, { headers }) => {
applyMiddleware (req, next) {
if (!req.options.headers) {
req.options.headers = {} // Create the header object if needed.
}
const token = getToken() const token = getToken()
req.options.headers.authorization = token ? `Bearer ${token}` : null return {
next() headers: {
...headers,
authorization: token ? `Bearer ${token}` : null
}
} }
}]) })
return new ApolloClient({ return new ApolloClient({
initialState, connectToDevTools: process.browser,
ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once) ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)
networkInterface link: authLink.concat(httpLink),
cache: new InMemoryCache().restore(initialState || {})
}) })
} }
......
...@@ -2,13 +2,14 @@ import React from 'react' ...@@ -2,13 +2,14 @@ import React from 'react'
import cookie from 'cookie' import cookie from 'cookie'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import { ApolloProvider, getDataFromTree } from 'react-apollo' import { ApolloProvider, getDataFromTree } from 'react-apollo'
import Head from 'next/head'
import initApollo from './initApollo' import initApollo from './initApollo'
function parseCookies (ctx = {}, options = {}) { function parseCookies(context = {}, options = {}) {
return cookie.parse( return cookie.parse(
ctx.req && ctx.req.headers.cookie context.req && context.req.headers.cookie
? ctx.req.headers.cookie ? context.req.headers.cookie
: document.cookie, : document.cookie,
options options
) )
...@@ -21,7 +22,7 @@ export default ComposedComponent => { ...@@ -21,7 +22,7 @@ export default ComposedComponent => {
serverState: PropTypes.object.isRequired serverState: PropTypes.object.isRequired
} }
static async getInitialProps (context) { static async getInitialProps(context) {
let serverState = {} let serverState = {}
// Setup a server-side one-time-use apollo client for initial props and // Setup a server-side one-time-use apollo client for initial props and
...@@ -46,9 +47,9 @@ export default ComposedComponent => { ...@@ -46,9 +47,9 @@ export default ComposedComponent => {
} }
// Provide the `url` prop data in case a graphql query uses it // Provide the `url` prop data in case a graphql query uses it
const url = {query: context.query, pathname: context.pathname} const url = { query: context.query, pathname: context.pathname }
try {
// Run all graphql queries // Run all GraphQL queries
const app = ( const app = (
<ApolloProvider client={apollo}> <ApolloProvider client={apollo}>
<ComposedComponent url={url} {...composedInitialProps} /> <ComposedComponent url={url} {...composedInitialProps} />
...@@ -61,15 +62,17 @@ export default ComposedComponent => { ...@@ -61,15 +62,17 @@ export default ComposedComponent => {
asPath: context.asPath asPath: context.asPath
} }
}) })
} catch (error) {
// Prevent Apollo Client GraphQL errors from crashing SSR.
// Handle them in components via the data.error prop:
// http://dev.apollodata.com/react/api-queries.html#graphql-query-data-error
}
// getDataFromTree does not call componentWillUnmount
// head side effect therefore need to be cleared manually
Head.rewind()
// Extract query data from the Apollo's store // Extract query data from the Apollo's store
const state = apollo.getInitialState() serverState = apollo.cache.extract()
serverState = {
apollo: { // Make sure to only include Apollo's data state
data: state.data
}
}
} }
return { return {
...@@ -78,7 +81,7 @@ export default ComposedComponent => { ...@@ -78,7 +81,7 @@ export default ComposedComponent => {
} }
} }
constructor (props) { constructor(props) {
super(props) super(props)
// Note: Apollo should never be used on the server side beyond the initial // Note: Apollo should never be used on the server side beyond the initial
// render within `getInitialProps()` above (since the entire prop tree // render within `getInitialProps()` above (since the entire prop tree
...@@ -89,7 +92,7 @@ export default ComposedComponent => { ...@@ -89,7 +92,7 @@ export default ComposedComponent => {
}) })
} }
render () { render() {
return ( return (
<ApolloProvider client={this.apollo}> <ApolloProvider client={this.apollo}>
<ComposedComponent {...this.props} /> <ComposedComponent {...this.props} />
......
...@@ -10,13 +10,15 @@ ...@@ -10,13 +10,15 @@
"test": "NODE_ENV=test ava" "test": "NODE_ENV=test ava"
}, },
"dependencies": { "dependencies": {
"apollo-client-preset": "1.0.2",
"apollo-link-context": "1.0.0",
"cookie": "^0.3.1", "cookie": "^0.3.1",
"graphql": "^0.9.3", "graphql": "0.11.7",
"isomorphic-fetch": "^2.2.1", "isomorphic-unfetch": "^2.0.0",
"next": "latest", "next": "latest",
"prop-types": "^15.5.10", "prop-types": "^15.5.10",
"react": "^16.0.0", "react": "^16.0.0",
"react-apollo": "^1.1.3", "react-apollo": "2.0.0",
"react-dom": "^16.0.0" "react-dom": "^16.0.0"
}, },
"devDependencies": { "devDependencies": {
......
...@@ -7,6 +7,17 @@ https://next-with-apollo.now.sh ...@@ -7,6 +7,17 @@ https://next-with-apollo.now.sh
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example with-apollo with-apollo-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -67,7 +67,7 @@ function PostList ({ data: { loading, error, allPosts, _allPostsMeta }, loadMore ...@@ -67,7 +67,7 @@ function PostList ({ data: { loading, error, allPosts, _allPostsMeta }, loadMore
return <div>Loading</div> return <div>Loading</div>
} }
const allPosts = gql` export const allPosts = gql`
query allPosts($first: Int!, $skip: Int!) { query allPosts($first: Int!, $skip: Int!) {
allPosts(orderBy: createdAt_DESC, first: $first, skip: $skip) { allPosts(orderBy: createdAt_DESC, first: $first, skip: $skip) {
id id
...@@ -81,15 +81,16 @@ const allPosts = gql` ...@@ -81,15 +81,16 @@ const allPosts = gql`
} }
} }
` `
export const allPostsQueryVars = {
skip: 0,
first: POSTS_PER_PAGE
}
// The `graphql` wrapper executes a GraphQL query and makes the results // The `graphql` wrapper executes a GraphQL query and makes the results
// available on the `data` prop of the wrapped component (PostList) // available on the `data` prop of the wrapped component (PostList)
export default graphql(allPosts, { export default graphql(allPosts, {
options: { options: {
variables: { variables: allPostsQueryVars
skip: 0,
first: POSTS_PER_PAGE
}
}, },
props: ({ data }) => ({ props: ({ data }) => ({
data, data,
......
import { graphql } from 'react-apollo' import { graphql } from 'react-apollo'
import gql from 'graphql-tag' import gql from 'graphql-tag'
import {allPosts, allPostsQueryVars} from './PostList'
function Submit ({ createPost }) { function Submit ({ createPost }) {
function handleSubmit (e) { function handleSubmit (e) {
...@@ -65,14 +66,9 @@ export default graphql(createPost, { ...@@ -65,14 +66,9 @@ export default graphql(createPost, {
props: ({ mutate }) => ({ props: ({ mutate }) => ({
createPost: (title, url) => mutate({ createPost: (title, url) => mutate({
variables: { title, url }, variables: { title, url },
updateQueries: { update: (proxy, { data: { createPost } }) => {
allPosts: (previousResult, { mutationResult }) => { const data = proxy.readQuery({ query: allPosts, variables: allPostsQueryVars })
const newPost = mutationResult.data.createPost proxy.writeQuery({ query: allPosts, data: {allPosts: [createPost, ...data.allPosts]}, variables: allPostsQueryVars })
return Object.assign({}, previousResult, {
// Append the new post
allPosts: [newPost, ...previousResult.allPosts]
})
}
} }
}) })
}) })
......
import { ApolloClient } from 'apollo-client' import { ApolloClient } from 'apollo-client'
import { HttpLink } from 'apollo-link-http' import { HttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory' import { InMemoryCache } from 'apollo-cache-inmemory'
import fetch from 'isomorphic-fetch' import fetch from 'isomorphic-unfetch'
let apolloClient = null let apolloClient = null
...@@ -16,9 +16,7 @@ function create (initialState) { ...@@ -16,9 +16,7 @@ function create (initialState) {
ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once) ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)
link: new HttpLink({ link: new HttpLink({
uri: 'https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn', // Server URL (must be absolute) uri: 'https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn', // Server URL (must be absolute)
opts: {
credentials: 'same-origin' // Additional fetch() options like `credentials` or `headers` credentials: 'same-origin' // Additional fetch() options like `credentials` or `headers`
}
}), }),
cache: new InMemoryCache().restore(initialState || {}), cache: new InMemoryCache().restore(initialState || {}),
}) })
......
...@@ -17,7 +17,12 @@ export default ComposedComponent => { ...@@ -17,7 +17,12 @@ export default ComposedComponent => {
} }
static async getInitialProps (ctx) { static async getInitialProps (ctx) {
let serverState = {} // Initial serverState with apollo (empty)
let serverState = {
apollo: {
data: { }
}
}
// Evaluate the composed component's getInitialProps() // Evaluate the composed component's getInitialProps()
let composedInitialProps = {} let composedInitialProps = {}
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
"graphql": "^0.11.7", "graphql": "^0.11.7",
"graphql-anywhere": "^3.1.0", "graphql-anywhere": "^3.1.0",
"graphql-tag": "^2.5.0", "graphql-tag": "^2.5.0",
"isomorphic-fetch": "^2.2.1", "isomorphic-unfetch": "^2.0.0",
"next": "latest", "next": "latest",
"prop-types": "^15.5.8", "prop-types": "^15.5.8",
"react": "^16.0.0", "react": "^16.0.0",
......
...@@ -2,6 +2,17 @@ ...@@ -2,6 +2,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example with-asset-imports with-asset-imports-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example with-babel-macros with-babel-macros-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example with-cxs with-cxs-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example with-dotenv with-dotenv-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -2,6 +2,17 @@ ...@@ -2,6 +2,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example with-dynamic-import with-dynamic-import-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -2,7 +2,18 @@ ...@@ -2,7 +2,18 @@
**You can find a detailed documentation about how to build Electron apps with Next.js [here](https://leo.im/2017/electron-next)!** **You can find a detailed documentation about how to build Electron apps with Next.js [here](https://leo.im/2017/electron-next)!**
## Usage ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example with-electron with-electron-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example with-emotion with-emotion-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example with-fela with-fela-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example with-firebase-authentication with-firebase-authentication-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
"express-session": "^1.15.2", "express-session": "^1.15.2",
"firebase": "^3.7.5", "firebase": "^3.7.5",
"firebase-admin": "^4.2.0", "firebase-admin": "^4.2.0",
"isomorphic-fetch": "2.2.1", "isomorphic-unfetch": "2.0.0",
"next": "latest", "next": "latest",
"react": "^16.0.0", "react": "^16.0.0",
"react-dom": "^16.0.0", "react-dom": "^16.0.0",
......
import React, { Component } from 'react' import React, { Component } from 'react'
import firebase from 'firebase' import firebase from 'firebase'
import 'isomorphic-fetch' import 'isomorphic-unfetch'
import clientCredentials from '../credentials/client' import clientCredentials from '../credentials/client'
export default class Index extends Component { export default class Index extends Component {
...@@ -33,7 +33,7 @@ export default class Index extends Component { ...@@ -33,7 +33,7 @@ export default class Index extends Component {
firebase.auth().onAuthStateChanged(user => { firebase.auth().onAuthStateChanged(user => {
if (user) { if (user) {
this.setState({ user: user }) this.setState({ user: user })
return user.getToken() return user.getIdToken()
.then((token) => { .then((token) => {
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
return fetch('/api/login', { return fetch('/api/login', {
......
...@@ -2,6 +2,17 @@ ...@@ -2,6 +2,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example with-firebase-hosting with-firebase-hosting-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
[ignore] [ignore]
.*/node_modules/*
[include] [include]
......
...@@ -3,6 +3,17 @@ ...@@ -3,6 +3,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example with-flow with-flow-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
// @flow // @flow
import type {Element} from 'React' import * as React from 'react'
import Link from 'next/link' import Link from 'next/link'
import Head from 'next/head' import Head from 'next/head'
type Props = { type Props = {
children?: Element<any>, children?: React.Element<any>,
title?: string title?: string
} }
......
...@@ -17,6 +17,6 @@ ...@@ -17,6 +17,6 @@
"devDependencies": { "devDependencies": {
"babel-eslint": "^7.1.1", "babel-eslint": "^7.1.1",
"babel-plugin-transform-flow-strip-types": "^6.21.0", "babel-plugin-transform-flow-strip-types": "^6.21.0",
"flow-bin": "^0.37.4" "flow-bin": "^0.59.0"
} }
} }
// @flow // @flow
import * as React from 'react'
import Layout from '../components/layout' import Layout from '../components/layout'
export default () => ( export default () => (
......
// @flow // @flow
import * as React from 'react'
import Layout from '../components/layout' import Layout from '../components/layout'
export default () => ( export default () => (
......
// @flow // @flow
import * as React from 'react'
import Layout from '../components/layout' import Layout from '../components/layout'
export default () => ( export default () => (
......
...@@ -13,15 +13,15 @@ declare module "next" { ...@@ -13,15 +13,15 @@ declare module "next" {
} }
declare module "next/head" { declare module "next/head" {
declare module.exports: Class<React$Component<void, any, any>>; declare module.exports: Class<React$Component<any, any>>;
} }
declare module "next/link" { declare module "next/link" {
declare module.exports: Class<React$Component<void, {href: string, prefetch?: bool}, any>>; declare module.exports: Class<React$Component<{href: string, prefetch?: bool}, any>>;
} }
declare module "next/error" { declare module "next/error" {
declare module.exports: Class<React$Component<void, {statusCode: number}, any>>; declare module.exports: Class<React$Component<{statusCode: number}, any>>;
} }
declare module "next/router" { declare module "next/router" {
...@@ -38,10 +38,10 @@ declare module "next/router" { ...@@ -38,10 +38,10 @@ declare module "next/router" {
} }
declare module "next/document" { declare module "next/document" {
declare export var Head: Class<React$Component<void, any, any>>; declare export var Head: Class<React$Component<any, any>>;
declare export var Main: Class<React$Component<void, any, any>>; declare export var Main: Class<React$Component<any, any>>;
declare export var NextScript: Class<React$Component<void, any, any>>; declare export var NextScript: Class<React$Component<any, any>>;
declare export default Class<React$Component<void, any, any>> & { declare export default Class<React$Component<any, any>> & {
getInitialProps: (ctx: {pathname: string, query: any, req?: any, res?: any, jsonPageRes?: any, err?: any}) => Promise<any>; getInitialProps: (ctx: {pathname: string, query: any, req?: any, res?: any, jsonPageRes?: any, err?: any}) => Promise<any>;
renderPage(cb: Function): void; renderPage(cb: Function): void;
}; };
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example with-freactal with-freactal-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
/* global fetch */ /* global fetch */
import 'isomorphic-fetch' import 'isomorphic-unfetch'
const API_BASE_URL = 'https://api.github.com' const API_BASE_URL = 'https://api.github.com'
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
}, },
"dependencies": { "dependencies": {
"freactal": "^1.1.1", "freactal": "^1.1.1",
"isomorphic-fetch": "^2.2.1", "isomorphic-unfetch": "^2.0.0",
"next": "latest", "next": "latest",
"react": "^16.0.0", "react": "^16.0.0",
"react-dom": "^16.0.0" "react-dom": "^16.0.0"
......
...@@ -4,6 +4,17 @@ ...@@ -4,6 +4,17 @@
## How to use ## How to use
### Using `create-next-app`
Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example:
```
npm i -g create-next-app
create-next-app --example with-glamor with-glamor-app
```
### Download manually
Download the example [or clone the repo](https://github.com/zeit/next.js): Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash ```bash
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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