Skip to content

Commit

Permalink
Auth example branch update (#1029)
Browse files Browse the repository at this point in the history
* chore(package): update babel-preset-env to version 1.1.5 (#660)

* chore(package): update webpack-hot-middleware to version 2.15.0 (#654)

* chore(package): update gulp-jest to version 1.0.0 (#653)

* Prevent prefetcher from making identical requests. (#665)

* example using inferno v1.0.* (#663)

* example using inferno v1.0.*

* fix name.

* Handle errors of React lifecycle methods (#661)

* handle errors of lifecycle methods

* handle errors of render method

* set output.strictModuleExceptionHandling option (#655)

* fix HMR for dynamic entries (#652)

* Fix Improve "pages/ not found error" (#624)

* fix not found error

* add comment

* Added layout component example (#560)

* added layout component example

* coding style fixes

* trailing spaces removed

* updated README file

* added layout example in docs

* moved .babelrc so that it handles all projects from the examples folder

* Release 2.0.0-beta.14

* bump styled-jsx

* Release 2.0.0-beta.15

* Adds mobx example (#676)

* Adds mobx example

* Fix coding style to match JS Standard

* Removes unecessary link

* Update README.md

* Update README.md

* Change next version from beta to ^2.0.0-beta

* Assigns the store to a local var

* Adds navigation in the example

* Removes unecessary imports

* Fix coding style to match JS Standard

* Fix Clock import

* bypass SSE on Service Worker (#681)

* fix HMR (#680)

* Release 2.0.0-beta.16

* Update README.md (#687)

* chore(package): update babel-preset-env to version 1.1.6 (#685)

* chore(package): update react to version 15.4.2 (#683)

* chore(package): update react-dom to version 15.4.2 (#682)

* hot-reloader: return when rejected (#689)

* resolve react-dom/server (#688)

* Routing on the client with Redux (#691)

* Routing on the client with Redux

* Removing unused import

* Fix link (#701)

* chore(package): update styled-jsx to version 0.4.1 (#700)

* Add correct content-type header for gzipped version. (#705)

* Add case sensitive checks for imports and JSON page resolver (#697)

* Add case-sensitive-paths-webpack-plugin plugin.

* Add case-sensitive check for server/resolve.

* Check the existence of the gzipped path explicitly (#704)

* Check the existance of the gzipped path explicitely.

* Fix a typo in the comments.

* Fix a typo.

* Use next.js beta for example (#710)

* Add custom server example using Hapi (#712)

* Fix title of README (#720)

* Adding polyfill to Headers.getAll to make it work both with the current and past spec. (#723)

* chore(package): update babel-preset-env to version 1.1.8 (#726)

* adding @timneutkens

* Add warning when running start without build (#736)

* add warning when running start without build

* run build before start

* Revert "run build before start"

This reverts commit 171b544.

* exit code & dir

* dont update yarn.lock

* use existsSync

* Add some style changes.

* Implement "Immutable build artifacts" feature (#745)

* Write BUILD_ID when building.
It's a random id (uuid.v4())

* Add buildId to the core JS files.

* Add immutable cache-control header.
Only if the buildId is matched.

* Set '-' as the dev buildId always.

* Add buildId handling for JSON pages.

* Remove default next pages compilation from the main babel-loader. (#731)

* Remove default next pages compilation from the main babel-loader.
This will fix the issue when the user ignore node_modules
via our .babelrc option.

* Change babel-loaders 'query' to 'options'.
That's what's supported/recommended in webpack 2

* Don't discard component state on error (#741)

* render debug page as overlay

* handle errors occurrred on rendering cycle for HMR

* retrieve props if required on HMR

* remove unused module alias

* New test setup (#640)

* Use jest-cli instead of gulp plugin.

* Use jest-cli instead of gulp plugin.

* Move fixtures into the examples dir.

* Move test code of example app to the basic example.

* Add isolated tests for server/resolve

* Allow tests to use cheerio.

* Use portfinder to get a unique port.

* Move back integration tests into the example dir.

* Introduce next-test-utils.

* Remove gulp-jest

* Add coveralls support.

* Use transpiled version of code in dist.
This is to make sure same file gets covered
by both unit/isolated tests and integration tests.

* Add support for source maps.

* Use code from dist always.

* Use nyc to stop instrument.

* Add integration test suite for production usage.

* Use jest-cli.

* Add support for running e2e tests.

* Check gzipPath with fs.stat before serving
Otherwise, serve package might throw issues other than ENOENT

* Install chromedriver with npm install.

* Install chrome on travis-ci.

* Add --forceExit to Jest.

* Run tests only on Node v6.
That's because selenium-webdriver only supports
Node 6 LTS.

* Use chromedriver NPM module to install chromedriver.

* Use wd as the webdriver client.

* Run chromedriver before tests.

* Run travis for both node 4 and 6

* Remove unwanted npm install script.

* Move some common text utilities to next-test-utils

* Add lint checks and testing in npm prepublish hook.

* Use npm on travis-ci.
We are having some caching issues with yarn and chromedriver.

* Make tests work on windows.\n But chromedriver doesn't work.

* Clean up dependencies.

* Run chromedriver in background without any tools.

* Fix a typo in the code.

* Use ES6 features used in node4 inside the gulpfile.

* Add some comments.

* Add support for running in windows.

* Stop chromedriver properly on windows.

* Fix typos.

* Fix handling http methods (#748)

* support HEAD method

* respond with 501 if method is not GET or HEAD

* Use dynamic entry feature of webpack (#750)

* update webpack version and use dynamic entry feature of it

* fix typo

* bump the test timeout for macbook 12 users :D

* Release 2.0.0-beta.17

* Dont' override glamor methods, use a new object instead (#754)

* Revert "Dont' override glamor methods, use a new object instead (#754)" (#755)

This reverts commit 8651662.

* Use the preact-compat dist version. (#760)

* Only show deprecation when using next/css (#762)

* update styletron example to support multiple stylesheets (#763)

* example: fix style

* Fix typo for --help messages in /bin (#770)

* chore(package): update mime-types to version 2.1.14 (#772)

* Add correct sync version of error handling with existSync. (#769)

* Add correct sync version of error handling with existSync.

* Update utils.js

* chore(package): update source-map-support to version 0.4.9 (#777)

* Add cross browser stacktrace (#776)

* Add cross browser stacktrace

* Remove unused stack variable

* Use UTC time to avoid time differences (#782)

* chore(package): update styled-jsx to version 0.4.2 (#784)

* Set default NODE_ENV value. (#768)

* chore(package): update friendly-errors-webpack-plugin to version 1.1.3 (#783)

* Add styled-jsx-postcss example (#781)

* Add styled-jsx-postcss example

* Remove commented code

* Add NODE_PATH support for resolveLoaders as well. (#778)

* Add NODE_PATH support for resolveLoaders as well.

* Remove unwanted code.

* bump webpack

* Fix typo in README (#787)

* Add dynamic routing keyword (#788)

I was looking for "dynamic routing" in the examples and didn't find it because that keyword isn't used.

* chore(package): update styled-jsx to version 0.4.3 (#792)

* Remove useless config override (#790)

* Fixed hapi example (#795)

* Added deprecation message when adding an extra anchor in behalf of the user. (#797)

* Fix link (#789)

* Fix link

* Fix links

* Updated <Link> in repo, always wrapping an anchor. (#798)

* Update README.md (#802)

fix quotation mark

* chore(package): update glamor to version 2.20.22 (#804)

* Added Koa example (#800)

* Added Koa example

* Linted koa example

* chore(package): update source-map-support to version 0.4.10 (#809)

* Fix koa-404 issue by adding res.statusCode to 200 (#815)

* chore(package): update styled-jsx to version 0.4.4 (#817)

* fix not to overwrite the ignored option on Windows (#824)

* added  example with flow (#814)

* added  example with flow

* Fixed linting errors

* Custom server example with Hapi in README (#825)

* Move nextdata into nextScript and make Main return a single el (#831)

* chore(package): update babel-core to version 6.22.1 (#842)

* chore(package): update babel-runtime to version 6.22.0 (#840)

* chore(package): update babel-preset-react to version 6.22.0 (#839)

* chore(package): update babel-preset-es2015 to version 6.22.0 (#838)

* chore(package): update babel-plugin-transform-runtime to version 6.22.0 (#837)

* chore(package): update babel-plugin-transform-object-rest-spread to version 6.22.0 (#836)

* chore(package): update babel-plugin-transform-class-properties to version 6.22.0 (#835)

* chore(package): update babel-plugin-transform-async-to-generator to version 6.22.0 (#834)

* chore(package): update babel-generator to version 6.22.0 (#833)

* Make sure lastAppProps always have some value. (#829)

* Make sure lastAppProps always have some value.

* Revert "Make sure lastAppProps always have some value."

This reverts commit b4ae722.

* Throw an error, if we found an empty object from getInitialProps.

* Add proper tests for getInitialProps empty check.

* chore(package): update styled-jsx to version 0.4.5 (#847)

* bump `styled-jsx`

* Release 2.0.0-beta.18

* Use ErrorDebug component on error of react-hot-loader (#852)

* use ErrorDebug component for reporter of react-hot-loader

* app: fix props of ErrorDebug

* Update styled-component docs (#841)

* Add details to custom Document documentation

Custom document must be created at ./Pages/_document.js, which is not
noted in the README… so I updated it.

* Add note to styled-components example about existing issue

* Made phrasing a bit more clear

* Another phrasing update.

* from P to p

* chore(package): update husky to version 0.13.0 (#853)

* Fix error fonts (#826)

* add "consolas" font for windows

* fix too small font size in non-retina display

* tweak font sizes again 🙈

* Add Apollo example (#780)

* Add minimal apollo example

* Update apollo example README

* Update apollo example demo link in README

* Fix button styles

* Fix show more button

* Alias demo url

* Include the data field on the Apollo store when hydrating

* Revert

* Include the data field on the Apollo store when hydrating per tpreusse's suggestion.

* Add example to faq section in README

* Sort by newest; Add active state to buttons

* Make optimization suggestions

* Use process.browser; inline props

* Wrap render method created using class properties (2) (#856)

* wrap render method created using class properties

* use Boolean instead of double not-operator

* patch-react: move a comment

* chore(package): update husky to version 0.13.1 (#862)

* Example using Fela (#863)

* added example using fela

* update package-json

* removed nested routing test

* fixed linting issues

* fixed typo

* simpler flow task (#857)

* Added Google AMP example (#793)

* Added Google AMP example

* Added styles and a second page

* Using regular anchor since there is no client-side routing

* Added comment on react config for amp

* Added Fela Example to the CSS-in-JS <details> in README (#878)

* fix(package): update styled-jsx to version 0.5.1 (#879)

https://greenkeeper.io/

* Handles the initial popstate event of older version of Safari. (#870)

* Update Apollo Example (#888)

* Add minimal apollo example

* Update apollo example README

* Update apollo example demo link in README

* Fix button styles

* Fix show more button

* Alias demo url

* Include the data field on the Apollo store when hydrating

* Revert

* Include the data field on the Apollo store when hydrating per tpreusse's suggestion.

* Add example to faq section in README

* Sort by newest; Add active state to buttons

* Make optimization suggestions

* Use process.browser; inline props

* Pass wrapped component's initial props into component heirarchy if they exist

* Don't process.exit(null) when e.g build is `SIGKILL`ed (#887)

* update yarn.lock

* Release 2.0.0-beta.19

* Fix handling finished response (#889)

* allows to not return props if response is already finished on getInitialProps

* check res.finished after getInitialProps call of Document

* Add `next build` and `next start` to the first How to use sample (#894)

* Update README.md (#895)

Just adding download instructions

* Fix Apollo Example (#900)

* Add minimal apollo example

* Update apollo example README

* Update apollo example demo link in README

* Fix button styles

* Fix show more button

* Alias demo url

* Include the data field on the Apollo store when hydrating

* Revert

* Include the data field on the Apollo store when hydrating per tpreusse's suggestion.

* Add example to faq section in README

* Sort by newest; Add active state to buttons

* Make optimization suggestions

* Use process.browser; inline props

* Pass wrapped component's initial props into component heirarchy if they exist

* Remove unnecessary sorting of array

* fix(package): update styled-jsx to version 0.5.2 (#902)

https://greenkeeper.io/

* Release 2.0.0-beta.20

* chore(package): update gulp-notify to version 3.0.0 (#905)

https://greenkeeper.io/

* fix(package): update source-map-support to version 0.4.11 (#901)

https://greenkeeper.io/

* chore(package): update wd to version 1.1.3 (#906)

https://greenkeeper.io/

* examples/with-redux: remove global store (#908)

This patch removes the global `store` on the client. IMO this example
should avoid polluting the global namespace with simple scoping tricks
can solve the problem equally as well.

* Do not patch prototypes with render exposed only as a getter. (#898)

* Do not patch prototypes with render exposed only as a getter.

* Use Object.getOwnPropertyDescriptor to make things simpler.

* Get the prototype which has the render method.

* with-apollo: Don't store Redux store and Apollo client in global namespace (#909)

* Add yarn lockfile

* Avoid storing Redux store and Apollo client in global namespace + don't create Apollo client when already existing in browser

* Remove yarn.lock from examples (#912)

* Remove yarn.lock from examples

* Add yarn.lock to gitignore for examples

* Move yarn ignore to examples directory

* README: fix "Routing with lazy component loading" blob (#915)

Looks like `<Link>` was replaced with `\n` on accident

* fix typo (#916)

* fix(package): update webpack-hot-middleware to version 2.16.0 (#922)

https://greenkeeper.io/

* Use service-worker to fetch only JSON pages. (#924)

* Use service-worker to fetch only JSON pages.
We simply don't need to proxy other requests through that.
That's might cause some latency issues.

* Use a better regexp to identify JSON pages.

* fix(package): update webpack-hot-middleware to version 2.16.1 (#935)

https://greenkeeper.io/

* [WIP] Remember scroll position on error (#911)

* Remember scroll position on error

* Added comment + check if lastScroll was set

* Remove check for lastAppProps

* Use events to make scroll persistence dev-only

* Return EventEmitter from next()

* Update next-dev.js

* fix(package): update webpack to version 2.2.1 (#938)

https://greenkeeper.io/

* Add support for Webpack 2's tree-shaking (#926)

* Let webpack2 to handle ES2015 module system
Since Node.js can't do that, we need to transpile
ES2015 module system in the emit-file-loader.

* Use sourceMaps only in dev.

* Introduce a transform option to emit-file-loader
So, we can move our ES2015 transpile code with that option.

* Remove unwanted argument options.

* Update comments.

* Use dev flag instead of NODE_ENV

* Set dev variable consistent with examples (#939)

* Fix .json import issue (#944)

* Fix .json import error
This is a regression we've added by #926 (tree-shaking-support)

* Add a test case.

* add pretty message if port already in use(#927) (#932)

* add pretty message if port already use(#927)

* fix console async nature

* fix linter

* clean callbacks code

* Check package.json for the startup script

* fix path to package

* omit callback

* remove extra check, code execute in try block

* + reason for change start listen port of node http

* remove extra code for search package

* fix(package): update webpack-dev-middleware to version 1.10.0 (#948)

https://greenkeeper.io/

* Resolve preset es2015 from next directory (#949)

* Resolve styled-jsx/style when transpiling ES2015 modules. (#953)

* Allow parsed url to be passed down (#950)

* Allow parsed url to be passed down

* Update example to reflect url passing

* Check if passed url.query is empty

* Rename url to parsedUrl

* Added React-MD example (#940)

* fix(package): update styled-jsx to version 0.5.3 (#958)

https://greenkeeper.io/

* Fix typo in react-md example readme (#959)

* Release 2.0.0-beta.21

* examples/with-react-md: Fixed "Cannot read property 'focus' of undefined" (#961)

* Resolve all modules through module resolver (#963)

* Check if BUILD_ID is available before starting (#960)

* Check if BUILD_ID is available before starting

* Leave whitespace at end of file

* Release 2.0.0-beta.22

* Find custom babel config location properly. (#969)

* Find custom babel config location properly.
Earlier we simply check for the .bablerc file in the dir.
But the actual logic is much complex.
Now we are using the babel's actual logic to find the
custom config location.

* Fix failing tests.

* Add styled-jsx to babel plugins (#970)

* Resolve all modules through module resolver

* Add styled-jsx back

* Improve babel settings (#976)

* fix babelrc settings

* use only transform-es2015-modules-commonjs for transpiling emitting files

* Allow any element to be rendered under Link (#921)

* Allow any element to be rendered under Link

* Use Children.only instead of Children.map

* Remove check for multiple children since we already throw at 2+

* Clean up variables

* Release 2.0.0-beta.23

* Added universal configuration example (#991)

* Added universal configuration example

* Make example more clear

* Properly handle hash URL changes. (#996)

* Properly handle hash URL changes.

* Make sure we replace origin correctly.

* Get rid of RegExp for getUrl().

* Add next.js flowtype definition to with-flow example (#973)

* Add next.js flowtype definition to with-flow

* Add render api types for flow

* Add prefetch types

* Fix push/replace api types to promise

* [example] Progressive rendered application (#998)

* [add] example of a progressive rendered app

* [update] remove extra blank line

* [update] fix typo

* [update] more use cases

* [update] example link

* Update README.md

* [update] next.js dependency version

* [update] fix readme typos

* fix(package): update styled-jsx to version 0.5.4 (#1002)

https://greenkeeper.io/

* Pass parsed request-URL into the run-method (#1000)

* fix(package): update babel-plugin-module-resolver to version 2.5.0 (#1005)

https://greenkeeper.io/

* chore(package): update coveralls to version 2.11.16 (#1007)

https://greenkeeper.io/

* Add contributing.md (#1009)

* Add contributing.md

* Only reload example app on server changes

* Release 2.0.0-beta.24

* Update Apollo example (#1021)

* Add minimal apollo example

* Update apollo example README

* Update apollo example demo link in README

* Fix button styles

* Fix show more button

* Alias demo url

* Include the data field on the Apollo store when hydrating

* Revert

* Include the data field on the Apollo store when hydrating per tpreusse's suggestion.

* Add example to faq section in README

* Sort by newest; Add active state to buttons

* Make optimization suggestions

* Use process.browser; inline props

* Pass wrapped component's initial props into component heirarchy if they exist

* Remove unnecessary sorting of array

* Update Apollo example

* Remove trailing comma

* Update reduxRootKey

* Remove unnecessary babelrc
  • Loading branch information
timneutkens committed Feb 7, 2017
1 parent 6231d96 commit 9795256
Show file tree
Hide file tree
Showing 208 changed files with 4,475 additions and 1,820 deletions.
7 changes: 6 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
"transform-object-rest-spread",
"transform-class-properties",
"transform-runtime"
]
],
"env": {
"test": {
"plugins": ["istanbul"]
}
}
}
23 changes: 16 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
sudo: required
dist: trusty
addons:
apt:
sources:
- google-chrome
packages:
- google-chrome-stable
language: node_js
node_js:
- "node"
- "6"
- "4"
- "6"
cache:
yarn: true
directories:
- node_modules
install:
- curl -o- -L https://yarnpkg.com/install.sh | bash
- export PATH=$HOME/.yarn/bin:$PATH
- yarn --ignore-engines
before_install:
- rm yarn.lock
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- sleep 3
script:
- echo "No need to use npm test since it's done in the install section via 'npm prepublish'"
after_script: npm run coveralls
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Contributing to Next.js

Our Commitment to Open Source can be found [here](https://zeit.co/blog/oss)

1. [Fork](https://help.github.com/articles/fork-a-repo/) this repository to your own GitHub account and then [clone](https://help.github.com/articles/cloning-a-repository/) it to your local device.
2. Install the dependencies: `npm install`
3. Run `npm link` to link the local repo to NPM
4. Run npm run build in a new terminal to build and watch for code changes
5. Then npm link this repo inside any example app with `npm link next`
6. Then you can run your example app with the local version of Next.js (You may need to re-run the example app as you change server side code in the Next.js repository)
50 changes: 37 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ and add a script to your package.json like this:
```json
{
"scripts": {
"dev": "next"
"dev": "next",
"build": "next build",
"start": "next start"
}
}
```
Expand Down Expand Up @@ -94,8 +96,10 @@ export default () => (
#### CSS-in-JS

<p><details>
<summary><b>Examples</b></summary>
<ul><li><a href="./examples/with-styled-components">Styled components</a></li><li><a href="./examples/with-styletron">Styletron</a></li><li><a href="./examples/with-glamor">Glamor</a></li><li><a href="./examples/with-cxs">Cxs</a></li><li><a href="./examples/with-aphrodite">Aphrodite</a></li></ul>
<summary>
<b>Examples</b>
</summary>
<ul><li><a href="./examples/with-styled-components">Styled components</a></li><li><a href="./examples/with-styletron">Styletron</a></li><li><a href="./examples/with-glamor">Glamor</a></li><li><a href="./examples/with-cxs">Cxs</a></li><li><a href="./examples/with-aphrodite">Aphrodite</a></li><li><a href="./examples/with-fela">Fela</a></li></ul>
</details></p>

It's possible to use any existing CSS-in-JS solution. The simplest one is inline styles:
Expand All @@ -122,7 +126,10 @@ export default () => (

<p><details>
<summary><b>Examples</b></summary>
<ul><li><a href="./examples/head-elements">Head elements</a></li></ul>
<ul>
<li><a href="./examples/head-elements">Head elements</a></li>
<li><a href="./examples/layout-component">Layout component</a></li>
</ul>
</details></p>

We expose a built-in component for appending elements to the `<head>` of the page.
Expand Down Expand Up @@ -268,7 +275,7 @@ Here's a list of supported events:

> Here `url` is the URL shown in the browser. If you call `Router.push(url, as)` (or similar), then the value of `url` will be `as`.
Here's how to property listen to the router event `routeChangeStart`:
Here's how to properly listen to the router event `routeChangeStart`:

```js
Router.onRouteChangeStart = (url) => {
Expand Down Expand Up @@ -324,7 +331,7 @@ export default () => (
When this higher-level `<Link>` component is first used, the `ServiceWorker` gets installed. To turn off prefetching on a per-`<Link>` basis, you can use the `prefetch` attribute:

```jsx
<Link href='/contact' prefetch={false}>Home</Link>
<Link href='/contact' prefetch={false}><a>Home</a></Link>
```

#### Imperatively
Expand Down Expand Up @@ -353,6 +360,8 @@ export default ({ url }) => (
<ul>
<li><a href="./examples/custom-server">Basic custom server</a></li>
<li><a href="./examples/custom-server-express">Express integration</a></li>
<li><a href="./examples/custom-server-hapi">Hapi integration</a></li>
<li><a href="./examples/custom-server-koa">Koa integration</a></li>
<li><a href="./examples/parameterized-routing">Parameterized routing</a></li>
<li><a href="./examples/ssr-caching">SSR caching</a></li>
</ul>
Expand All @@ -367,19 +376,21 @@ const { createServer } = require('http')
const { parse } = require('url')
const next = require('next')

const app = next({ dev: true })
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()

app.prepare().then(() => {
createServer((req, res) => {
const { pathname, query } = parse(req.url, true)
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)
handle(req, res, parsedUrl)
}
})
.listen(3000, (err) => {
Expand All @@ -403,12 +414,14 @@ Supported options:
<p><details>
<summary><b>Examples</b></summary>
<ul><li><a href="./examples/with-styled-components">Styled components custom document</a></li></ul>
<ul><li><a href="./examples/with-amp">Google AMP</a></li></ul>
</details></p>

Pages in `Next.js` skip the definition of the surrounding document's markup. For example, you never include `<html>`, `<body>`, etc. But we still make it possible to override that:
Pages in `Next.js` skip the definition of the surrounding document's markup. For example, you never include `<html>`, `<body>`, etc. To override that default behavior, you must create a file at `./pages/_document.js`, where you can extend the `Document` class:

```jsx
import Document, { Head, Main, NextScript } from `next/document`
// ./pages/_document.js
import Document, { Head, Main, NextScript } from 'next/document'

export default class MyDocument extends Document {
static async getInitialProps (ctx) {
Expand Down Expand Up @@ -577,8 +590,7 @@ No in that it enforces a _structure_ so that we can do more advanced things like
- Automatic code splitting

In addition, Next.js provides two built-in features that are critical for every single website:
- Routing with lazy component loading: `
>` (by importing `next/link`)
- Routing with lazy component loading: `<Link>` (by importing `next/link`)
- A way for components to alter `<head>`: `<Head>` (by importing `next/head`)

If you want to create re-usable React components that you can embed in your Next.js app or other React applications, using `create-react-app` is a great idea. You can later `import` it and keep your codebase clean!
Expand Down Expand Up @@ -632,6 +644,13 @@ On the client side, we have a parameter call `as` on `<Link>` that _decorates_ t
It’s up to you. `getInitialProps` is an `async` function (or a regular function that returns a `Promise`). It can retrieve data from anywhere.
</details>

<details>
<summary>Can I use it with GraphQL?</summary>

Yes! Here's an example with [Apollo](./examples/with-apollo).

</details>

<details>
<summary>Can I use it with Redux?</summary>

Expand All @@ -655,9 +674,14 @@ As we were researching options for server-rendering React that didn’t involve

Our Roadmap towards 2.0.0 [is public](https://github.com/zeit/next.js/wiki/Roadmap#nextjs-200).

## Contributing

Please see our [CONTRIBUTING.md](./CONTRIBUTING.md)

## Authors

- Naoyuki Kanezawa ([@nkzawa](https://twitter.com/nkzawa)) – ▲ZEIT
- Tony Kovanen ([@tonykovanen](https://twitter.com/tonykovanen)) – ▲ZEIT
- Guillermo Rauch ([@rauchg](https://twitter.com/rauchg)) – ▲ZEIT
- Dan Zajdband ([@impronunciable](https://twitter.com/impronunciable)) – Knight-Mozilla / Coral Project
- Tim Neutkens ([@timneutkens](https://github.com/timneutkens))
14 changes: 13 additions & 1 deletion bin/next
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,19 @@ const bin = join(__dirname, 'next-' + cmd)

const startProcess = () => {
const proc = spawn(bin, args, { stdio: 'inherit', customFds: [0, 1, 2] })
proc.on('close', (code) => process.exit(code))
proc.on('close', (code, signal) => {
if (code !== null) {
process.exit(code)
}
if (signal) {
if (signal === 'SIGKILL') {
process.exit(137)
}
console.log(`got signal ${signal}, exitting`)
process.exit(1)
}
process.exit(0)
})
proc.on('error', (err) => {
console.error(err)
process.exit(1)
Expand Down
20 changes: 18 additions & 2 deletions bin/next-build
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/usr/bin/env node

import { resolve } from 'path'
import { resolve, join } from 'path'
import { existsSync } from 'fs'
import parseArgs from 'minimist'
import build from '../server/build'
import { printAndExit } from '../lib/utils'

process.env.NODE_ENV = process.env.NODE_ENV || 'production'

const argv = parseArgs(process.argv.slice(2), {
alias: {
Expand All @@ -27,6 +30,19 @@ if (argv.help) {

const dir = resolve(argv._[0] || '.')

// Check if pages dir exists and warn if not
if (!existsSync(dir)) {
printAndExit(`> No such directory exists as the project root: ${dir}`)
}

if (!existsSync(join(dir, 'pages'))) {
if (existsSync(join(dir, '..', 'pages'))) {
printAndExit('> No `pages` directory found. Did you mean to run `next` in the parent (`../`) directory?')
}

printAndExit('> Couldn\'t find a `pages` directory. Please create one under the project root')
}

build(dir)
.catch((err) => {
console.error(err)
Expand Down
44 changes: 30 additions & 14 deletions bin/next-dev
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
import 'source-map-support/register'
import { resolve, join } from 'path'
import parseArgs from 'minimist'
import { exists } from 'mz/fs'
import { existsSync, readFileSync } from 'fs'
import Server from '../server'
import { printAndExit } from '../lib/utils'
import pkgUp from 'pkg-up'

process.env.NODE_ENV = process.env.NODE_ENV || 'development'

const argv = parseArgs(process.argv.slice(2), {
alias: {
Expand All @@ -30,31 +34,43 @@ if (argv.help) {
Options
--port, -p A port number on which to start the application
--help, -p Displays this message
--help, -h Displays this message
`)
process.exit(0)
}

const dir = resolve(argv._[0] || '.')

// Check if pages dir exists and warn if not
if (!existsSync(dir)) {
printAndExit(`> No such directory exists as the project root: ${dir}`)
}

if (!existsSync(join(dir, 'pages'))) {
if (existsSync(join(dir, '..', 'pages'))) {
printAndExit('> No `pages` directory found. Did you mean to run `next` in the parent (`../`) directory?')
}

printAndExit('> Couldn\'t find a `pages` directory. Please create one under the project root')
}

const srv = new Server({ dir, dev: true })
srv.start(argv.port)
.then(async () => {
if (!process.env.NOW) {
console.log(`> Ready on http://localhost:${argv.port}`)
}

// Check if pages dir exists and warn if not
if (!(await exists(join(dir, 'pages')))) {
if (await exists(join(dir, '..', 'pages'))) {
console.error('> No `pages` directory found. Did you mean to run `next` in the parent (`../`) directory?')
} else {
console.error('> Couldn\'t find a `pages` directory. Please create one under the project root')
}
process.exit(1)
}
})
.catch((err) => {
console.error(err)
process.exit(1)
if (err.code === 'EADDRINUSE') {
let errorMessage = `Port ${argv.port} is already in use.`
const pkgAppPath = pkgUp.sync('.')
const appPackage = JSON.parse(readFileSync(pkgAppPath, 'utf8'))
const nextScript = Object.entries(appPackage.scripts).find(scriptLine => scriptLine[1] === 'next')
if (nextScript) errorMessage += `\nUse \`npm run ${nextScript[0]} -- -p <some other port>\`.`
console.error(errorMessage)
} else {
console.error(err)
}
process.nextTick(() => process.exit(1))
})
2 changes: 1 addition & 1 deletion bin/next-init
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if (argv.help) {
If no directory is provided the current directory will be used.
Options
--help, -p Displays this message
--help, -h Displays this message
`)

process.exit(0)
Expand Down
12 changes: 11 additions & 1 deletion bin/next-start
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import { resolve } from 'path'
import parseArgs from 'minimist'
import Server from '../server'
import { existsSync } from 'fs'

process.env.NODE_ENV = process.env.NODE_ENV || 'production'

const argv = parseArgs(process.argv.slice(2), {
alias: {
Expand Down Expand Up @@ -30,14 +33,20 @@ if (argv.help) {
Options
--port, -p A port number on which to start the application
--help, -p Displays this message
--help, -h Displays this message
`)
process.exit(0)
}

const dir = resolve(argv._[0] || '.')

const srv = new Server({ dir })

if (!existsSync(resolve(dir, '.next', 'BUILD_ID'))) {
console.error(`> Could not find a valid build in the '.next' directory! Try building your app with 'next build' before starting the server.`)
process.exit(1)
}

srv.start(argv.port)
.then(() => {
if (!process.env.NOW) {
Expand All @@ -48,3 +57,4 @@ srv.start(argv.port)
console.error(err)
process.exit(1)
})

Loading

0 comments on commit 9795256

Please sign in to comment.