Skip to content

Add custom-server-express example - #352

Merged
nkzawa merged 3 commits into
vercel:add/programmatic-apifrom
jaredpalmer:add/express-example
Dec 13, 2016
Merged

nkzawa merged 3 commits into
vercel:add/programmatic-apifrom
jaredpalmer:add/express-example

Conversation

@jaredpalmer

@jaredpalmer jaredpalmer commented Dec 6, 2016 •

Copy link
Copy Markdown
Contributor

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.

next()
})

server.get('/a', (req, res, next) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need next argument here and the following cases.

@coveralls

coveralls commented Dec 7, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 48.229% when pulling 621599b on jaredpalmer:add/express-example into 4fe3ba8 on zeit:add/programmatic-api.

@coveralls

coveralls commented Dec 7, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 48.229% when pulling 6959754 on jaredpalmer:add/express-example into 4fe3ba8 on zeit:add/programmatic-api.

@rauchg

rauchg commented Dec 7, 2016

Copy link
Copy Markdown
Member

This is so beautiful @jaredpalmer

.then(() => {
const server = express()

server.use((req, res, next) => {

@arunoda arunoda Dec 7, 2016 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arunoda if not then, I would wantserver.use(nextMiddleware)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nkzawa why did we not handle json directly in the render helper?

@nkzawa nkzawa Dec 9, 2016 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Briliant

@jaredpalmer

Copy link
Copy Markdown
Contributor Author

@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 })

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first argument is also optional and . is default, so it should be

next({ dev: true })

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that explicit is better than implicit; please, don't hide this feature in the example.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nkzawa whats the verdict?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about adding a comment in the example stating The first argument is also optional and . is default

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 })

@chr1shaefn3r chr1shaefn3r mentioned this pull request Dec 8, 2016
@coveralls

coveralls commented Dec 9, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 48.229% when pulling 8722927 on jaredpalmer:add/express-example into 4fe3ba8 on zeit:add/programmatic-api.

1 similar comment
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 48.229% when pulling 8722927 on jaredpalmer:add/express-example into 4fe3ba8 on zeit:add/programmatic-api.

@jaredpalmer

Copy link
Copy Markdown
Contributor Author

What's the status of this?

@nkzawa
nkzawa merged commit 8318728 into vercel:add/programmatic-api Dec 13, 2016
@nkzawa

nkzawa commented Dec 13, 2016

Copy link
Copy Markdown
Contributor

@jaredpalmer merged, thanks!

rauchg pushed a commit that referenced this pull request Dec 16, 2016
* 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
@lock lock Bot locked as resolved and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants