-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
doc: Add documentation about client-generator-nextjs #822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dunglas
merged 4 commits into
api-platform:2.4
from
Gregcop1:feat-client-generator-nextjs
Jun 11, 2019
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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,109 @@ | ||
# Next.js Generator | ||
|
||
 | ||
|
||
The Next.js Client Generator generates routes and components for Server Side Rendered applications using [Next.js](https://zeit.co/blog/next) | ||
|
||
## Install | ||
|
||
### Next + Express Server | ||
|
||
Create a [Next.js application with express server](https://github.com/zeit/next.js/tree/canary/examples/custom-server-express). The easiest way is to execute: | ||
|
||
```bash | ||
$ npx create-next-app --example custom-server-express your-app-name | ||
# or | ||
$ yarn create next-app --example custom-server-express your-app-name | ||
``` | ||
|
||
### Enabling Typescript | ||
|
||
Install typescript dependencies | ||
|
||
```bash | ||
$ yarn add @types/next @zeit/next-typescript | ||
``` | ||
|
||
Enable Typescript in your Next.js configuration file (`next.config.js`): | ||
|
||
```javascript | ||
const withTypescript = require('@zeit/next-typescript'); | ||
|
||
module.exports = withTypescript(); | ||
``` | ||
|
||
Create a `.babelrc` file to store Babel configuration: | ||
```json | ||
{ | ||
"presets": [ | ||
"next/babel", | ||
"@zeit/next-typescript/babel" | ||
] | ||
} | ||
``` | ||
|
||
Create a `tsconfig.json` file to store Typescript configuration: | ||
```json | ||
{ | ||
"compilerOptions": { | ||
"allowJs": true, | ||
"allowSyntheticDefaultImports": true, | ||
"jsx": "preserve", | ||
"lib": ["dom", "es2017"], | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"noEmit": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"preserveConstEnums": true, | ||
"removeComments": false, | ||
"skipLibCheck": true, | ||
"sourceMap": true, | ||
"strict": true, | ||
"target": "esnext", | ||
"typeRoots": [ | ||
"node_modules/@types" | ||
] | ||
} | ||
} | ||
``` | ||
|
||
### Installing the Generator Dependencies | ||
|
||
Install required dependencies: | ||
|
||
```bash | ||
$ yarn add lodash.get lodash.has @types/lodash isomorphic-unfetch | ||
``` | ||
|
||
## Starting the Project | ||
|
||
You can launch the server with | ||
```bash | ||
$ yarn dev | ||
``` | ||
|
||
and access it through `http://localhost:3000` | ||
|
||
## Generating Routes | ||
|
||
```bash | ||
$ npx @api-platform/client-generator https://demo.api-platform.com src/ --generator next --resource book | ||
# Replace the URL by the entrypoint of your Hydra-enabled API | ||
``` | ||
|
||
> Note: Omit the resource flag to generate files for all resource types exposed by the API. | ||
|
||
If your express server is compatible with the `custom-server-express` Next.js example, you can use the `server-path` flag to specify path to the server file. Routes will be added automatically to this file, otherwise, you will receive some hints on how to them to your own custom server. | ||
Gregcop1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```bash | ||
$ npx @api-platform/client-generator https://demo.api-platform.com src/ --generator next --server-path ./server.js | ||
``` | ||
|
||
Go to `https://localhost:3000/books/` to start using your app. | ||
That's it! | ||
|
||
## Screenshots | ||
|
||
 | ||
 |
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.