Skip to content

Commit

Permalink
Merge branch 'canary' of github.com:zeit/next.js into canary
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens committed Mar 30, 2020
2 parents e7ea276 + e4bf0d4 commit dd098ca
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 51 deletions.
2 changes: 1 addition & 1 deletion docs/api-routes/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default (req, res) => {

To fetch API endpoints, take a look into any of the examples at the start of this section.

> API Routes [do not specify CORS headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS), meaning they are **same-origin only** by default. You can customize such behavior by wrapping the request handler with [micro-cors](/docs/api-routes/api-middlewares.md#micro-support).
> API Routes [do not specify CORS headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS), meaning they are **same-origin only** by default. You can customize such behavior by wrapping the request handler with the [cors middleware](/docs/api-routes/api-middlewares.md#connectexpress-middleware-support).
> API Routes do not increase your client-side bundle size. They are server-side only bundles.
Expand Down
2 changes: 1 addition & 1 deletion docs/routing/dynamic-routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description: Dynamic Routes are pages that allow you to add custom params to you
</ul>
</details>

Defining routes by using predefined paths is not always enough for complex applications, in Next.js you can add brackets to a page (`[param]`) to create a dynamic route (a.k.a. url slugs, pretty urls, and others).
Defining routes by using predefined paths is not always enough for complex applications. In Next.js you can add brackets to a page (`[param]`) to create a dynamic route (a.k.a. url slugs, pretty urls, and others).

Consider the following page `pages/post/[pid].js`:

Expand Down
4 changes: 2 additions & 2 deletions examples/api-routes-rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"start": "next start"
},
"dependencies": {
"isomorphic-unfetch": "3.0.0",
"next": "latest",
"react": "^16.8.6",
"react-dom": "^16.8.6"
"react-dom": "^16.8.6",
"swr": "^0.1.18"
},
"license": "ISC"
}
8 changes: 1 addition & 7 deletions examples/api-routes-rest/pages/api/users.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
// Fake users data
const users = [
{
id: 1,
},
{ id: 2 },
{ id: 3 },
]
const users = [{ id: 1 }, { id: 2 }, { id: 3 }]

export default (req, res) => {
// Get data from your database
Expand Down
36 changes: 18 additions & 18 deletions examples/api-routes-rest/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import fetch from 'isomorphic-unfetch'
import useSwr from 'swr'
import Link from 'next/link'

const Index = ({ users }) => (
<ul>
{users.map(user => (
<li key={user.id}>
<Link href="/user/[id]" as={`/user/${user.id}`}>
<a>{`User ${user.id}`}</a>
</Link>
</li>
))}
</ul>
)
const fetcher = url => fetch(url).then(res => res.json())

Index.getInitialProps = async () => {
const response = await fetch('http://localhost:3000/api/users')
const users = await response.json()
export default function Index() {
const { data, error } = useSwr('/api/users', fetcher)

return { users }
}
if (error) return <div>Failed to load users</div>
if (!data) return <div>Loading...</div>

export default Index
return (
<ul>
{data.map(user => (
<li key={user.id}>
<Link href="/user/[id]" as={`/user/${user.id}`}>
<a>{`User ${user.id}`}</a>
</Link>
</li>
))}
</ul>
)
}
18 changes: 10 additions & 8 deletions examples/api-routes-rest/pages/user/[id].js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import fetch from 'isomorphic-unfetch'
import { useRouter } from 'next/router'
import useSwr from 'swr'

const User = ({ user }) => <div>{user.name}</div>
const fetcher = url => fetch(url).then(res => res.json())

User.getInitialProps = async ({ query: { id } }, res) => {
const response = await fetch(`http://localhost:3000/api/user/${id}`)
const user = await response.json()
export default function User() {
const router = useRouter()
const { data, error } = useSwr(`/api/user/${router.query.id}`, fetcher)

return { user }
}
if (error) return <div>Failed to load user</div>
if (!data) return <div>Loading...</div>

export default User
return <div>{data.name}</div>
}
2 changes: 1 addition & 1 deletion examples/custom-server-actionhero/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ module.exports = class CreateChatRoom extends Action {

3. Tell ActionHero to use the api rather than the file server as the top-level route in `api.config.servers.web.rootEndpointType = 'api'`. This will allows "/" to listen to API requests. Also update `api.config.general.paths.public = [ path.join(__dirname, '/../static') ]`. In this configuration, the next 'static' renderer will take priority over the ActionHero 'public file' api. Note that any static assets (CSS, fonts, etc) will need to be in "./static" rather than "./public".

Note that this is where the websocket server, if you enable it, will place the `ActionheroWebsocketClient` libraray.<br>
Note that this is where the websocket server, if you enable it, will place the `ActionheroWebsocketClient` library.<br>

4. Configure a wild-card route at the lowest priority of your GET handler to catch all web requests that aren't caught by other actions:

Expand Down
2 changes: 1 addition & 1 deletion examples/with-aphrodite/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Example app with aphrodite

This example features how yo use a different styling solution than [styled-jsx](https://github.com/zeit/styled-jsx) that also supports universal styles. That means we can serve the required styles for the first render within the HTML and then load the rest in the client. In this case we are using [Aphrodite](https://github.com/Khan/aphrodite/).
This example features how to use a different styling solution than [styled-jsx](https://github.com/zeit/styled-jsx) that also supports universal styles. That means we can serve the required styles for the first render within the HTML and then load the rest in the client. In this case we are using [Aphrodite](https://github.com/Khan/aphrodite/).

For this purpose we are extending the `<Document />` and injecting the server side rendered styles into the `<head>`.

Expand Down
10 changes: 5 additions & 5 deletions examples/with-emotion-11/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"author": "Thomas Greco",
"license": "ISC",
"dependencies": {
"@emotion/cache": "11.0.0-next.10",
"@emotion/css": "11.0.0-next.10",
"@emotion/react": "11.0.0-next.10",
"@emotion/server": "11.0.0-next.10",
"@emotion/styled": "11.0.0-next.10",
"@emotion/cache": "11.0.0-next.12",
"@emotion/css": "11.0.0-next.12",
"@emotion/react": "11.0.0-next.12",
"@emotion/server": "11.0.0-next.12",
"@emotion/styled": "11.0.0-next.12",
"next": "latest",
"react": "^16.7.0",
"react-dom": "^16.7.0"
Expand Down
1 change: 1 addition & 0 deletions examples/with-firebase-hosting-and-typescript/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dist/
node_modules/

# Firebase cache
.firebase/
4 changes: 2 additions & 2 deletions examples/with-sentry-simple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Deploy it to the cloud with [ZEIT Now](https://zeit.co/import?filter=next.js&utm
This is a simple example showing how to use [Sentry](https://sentry.io) to catch & report errors on both client + server side.

- `_app.js` renders on both the server and client. It initializes Sentry to catch any unhandled exceptions
- `_error.js` is rendered by Next.js while handling certain types of exceptions for you. It is overriden so those exceptions can be passed along to Sentry
- `_error.js` is rendered by Next.js while handling certain types of exceptions for you. It is overridden so those exceptions can be passed along to Sentry
- `next.config.js` enables source maps in production for Sentry and swaps out `@sentry/node` for `@sentry/browser` when building the client bundle

**Note**: Source maps will not be sent to Sentry when running locally (because Sentry cannot access your `localhost`). To accurately test client-side source maps, please deploy to Now.
Expand Down Expand Up @@ -84,7 +84,7 @@ Sentry.init({

### Hosting source maps vs. uploading them to Sentry

This example shows how to generate your own source maps, which are hosted alongside your JavaScript bundles in production. But that has the potential for innaccurate results in Sentry.
This example shows how to generate your own source maps, which are hosted alongside your JavaScript bundles in production. But that has the potential for inaccurate results in Sentry.

Sentry will attempt to [fetch the source map](https://docs.sentry.io/platforms/javascript/sourcemaps/#hosting--uploading) when it is processing an exception, as long as the "Enable JavaScript source fetching" setting is turned on for your Sentry project.

Expand Down
6 changes: 3 additions & 3 deletions packages/next-mdx/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ const withMDX = require('@next/mdx')()
module.exports = withMDX()
```

Optionally you can provide [MDX options](https://github.com/mdx-js/mdx#options):
Optionally you can provide [MDX plugins](https://mdxjs.com/advanced/plugins#plugins):

```js
// next.config.js
const withMDX = require('@next/mdx')({
options: {
mdPlugins: [],
hastPlugins: [],
remarkPlugins: [],
rehypePlugins: [],
},
})
module.exports = withMDX()
Expand Down
2 changes: 1 addition & 1 deletion packages/next/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<a aria-label="License" href="https://github.com/zeit/next.js/blob/canary/license.md">
<img alt="" src="https://img.shields.io/npm/l/next.svg?style=for-the-badge&labelColor=000000">
</a>
<a aria-label="join us in spectrum" href="https://github.com/zeit/next.js/discussions">
<a aria-label="Join the community on GitHub" href="https://github.com/zeit/next.js/discussions">
<img alt="" src="https://img.shields.io/badge/Join%20the%20community-blueviolet.svg?style=for-the-badge&logo=Next.js&labelColor=000000&logoWidth=20">
</a>
</p>
Expand Down
3 changes: 2 additions & 1 deletion packages/next/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import React from 'react'
import { ParsedUrlQuery } from 'querystring'
import { IncomingMessage, ServerResponse } from 'http'
import { Env } from '../lib/load-env-config'
// @ts-ignore This path is generated at build time and conflicts otherwise
import { Env } from '../dist/lib/load-env-config'

import {
NextPageContext,
Expand Down

0 comments on commit dd098ca

Please sign in to comment.