-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add 'next' api * add render APIs * add 'as' prop to Link * check Accept header to serve json response * check if response was finished on getInitialProps call * move server/app to server/index * load webpack-hot-middleware-client by absolute path * server: options for testing * add tests * example: improve * server: make dir optional * fix client routing * add parameterized routing example * link: fix display url * Add custom-server-express example (#352) * Add custom-server-express example * Remove extraneous nexts in express routes defs * Update next config in server.js * Handle accept headers totally inside Next.js (#385) * Handle accept headers totally inside Next.js Now user doesn't need to handle it anymore. * Move json pages serving to /_next/pages base path. * Join paths correctly. * remove next/render
- Loading branch information
Showing
28 changed files
with
440 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"scripts": { | ||
"start": "node server.js" | ||
}, | ||
"dependencies": { | ||
"accepts": "1.3.3", | ||
"express": "^4.14.0", | ||
"next": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import React from 'react' | ||
|
||
export default () => <div>a</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import React from 'react' | ||
|
||
export default () => <div>b</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
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> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const express = require('express') | ||
const next = require('next') | ||
|
||
const app = next({ dir: '.', dev: true }) | ||
const handle = app.getRequestHandler() | ||
|
||
app.prepare() | ||
.then(() => { | ||
const server = express() | ||
|
||
server.get('/a', (req, res) => { | ||
return app.render(req, res, '/b', req.query) | ||
}) | ||
|
||
server.get('/b', (req, res) => { | ||
return app.render(req, res, '/a', req.query) | ||
}) | ||
|
||
server.get('*', (req, res) => { | ||
return handle(req, res) | ||
}) | ||
|
||
server.listen(3000, (err) => { | ||
if (err) throw err | ||
console.log('> Ready on http://localhost:3000') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"scripts": { | ||
"start": "node server.js" | ||
}, | ||
"dependencies": { | ||
"accepts": "1.3.3", | ||
"next": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import React from 'react' | ||
|
||
export default () => <div>a</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import React from 'react' | ||
|
||
export default () => <div>b</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
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> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const { createServer } = require('http') | ||
const { parse } = require('url') | ||
const next = require('next') | ||
|
||
const app = next({ dev: true }) | ||
const handle = app.getRequestHandler() | ||
|
||
app.prepare() | ||
.then(() => { | ||
createServer((req, res) => { | ||
const { pathname, query } = parse(req.url, true) | ||
|
||
if (pathname === '/a') { | ||
app.render(req, res, '/b', query) | ||
} else if (pathname === '/b') { | ||
app.render(req, res, '/a', query) | ||
} else { | ||
handle(req, res) | ||
} | ||
}) | ||
.listen(3000, (err) => { | ||
if (err) throw err | ||
console.log('> Ready on http://localhost:3000') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"scripts": { | ||
"start": "node server.js" | ||
}, | ||
"dependencies": { | ||
"accepts": "1.3.3", | ||
"next": "*", | ||
"path-match": "1.2.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React, { Component } from 'react' | ||
|
||
export default class extends Component { | ||
static getInitialProps ({ query: { id } }) { | ||
return { id } | ||
} | ||
|
||
render () { | ||
return <div> | ||
<h1>My {this.props.id} blog post</h1> | ||
<p> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod | ||
tempor incididunt ut labore et dolore magna aliqua. | ||
</p> | ||
</div> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react' | ||
import Link from 'next/link' | ||
|
||
export default () => ( | ||
<ul> | ||
<li><Link href='/blog?id=first' as='/blog/first'><a>My first blog post</a></Link></li> | ||
<li><Link href='/blog?id=second' as='/blog/second'><a>My second blog post</a></Link></li> | ||
<li><Link href='/blog?id=last' as='/blog/last'><a>My last blog post</a></Link></li> | ||
</ul> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const { createServer } = require('http') | ||
const { parse } = require('url') | ||
const next = require('next') | ||
const pathMatch = require('path-match') | ||
|
||
const app = next({ dev: true }) | ||
const handle = app.getRequestHandler() | ||
const route = pathMatch() | ||
const match = route('/blog/:id') | ||
|
||
app.prepare() | ||
.then(() => { | ||
createServer((req, res) => { | ||
const { pathname } = parse(req.url) | ||
const params = match(pathname) | ||
if (params === false) { | ||
handle(req, res) | ||
return | ||
} | ||
|
||
app.render(req, res, '/blog', params) | ||
}) | ||
.listen(3000, (err) => { | ||
if (err) throw err | ||
console.log('> Ready on http://localhost:3000') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
1708222
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nkzawa @rauchg love this new API, it shoudl make writing tests for next apps way easier. I'd love to start playing with this at npm without installing from git, don't suppose I could convince you to release the update to a
beta
ornext
tag on npm?1708222
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bcoe we'll do that very shortly