Repository navigation
Add custom-server-express example - #352
Conversation
| next() | ||
| }) | ||
|
|
||
| server.get('/a', (req, res, next) => { |
There was a problem hiding this comment.
You don't need next argument here and the following cases.
|
This is so beautiful @jaredpalmer |
| .then(() => { | ||
| const server = express() | ||
|
|
||
| server.use((req, res, next) => { |
There was a problem hiding this comment.
@rauchg I wish we could have remove this by handling accept types inside app.render.
Then we don't need any server.use at all.
So, it's pretty damn easy for users to use this.
There was a problem hiding this comment.
@arunoda if not then, I would wantserver.use(nextMiddleware)
There was a problem hiding this comment.
@nkzawa why did we not handle json directly in the render helper?
There was a problem hiding this comment.
Because we want JSON endpoints to be fixed URL for component caching.
Additionally, we have the renderToHTML method which we have to detect if html is required or not anyway.
|
@rauchg thanks man. I appreciate all the work you and the zeit team do. |
| const next = require('next') | ||
| const accepts = require('accepts') | ||
|
|
||
| const app = next('.', { dev: true }) |
There was a problem hiding this comment.
The first argument is also optional and . is default, so it should be
next({ dev: true })
There was a problem hiding this comment.
I believe that explicit is better than implicit; please, don't hide this feature in the example.
There was a problem hiding this comment.
how about adding a comment in the example stating The first argument is also optional and . is default
There was a problem hiding this comment.
I have no strong opinion about this. Adding comments is also great.
btw my explanation might have been a bit confusing. You set dir like the following now.
next({ dir: '.', dev: true })
1 similar comment
|
What's the status of this? |
|
@jaredpalmer merged, thanks! |
* 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
I think the custom server example is fine, but it still took me a several minutes to setup express.
Adding this should help clarify a common use case and more importantly, demonstrate that migrating to next isn't too tough.