-
Notifications
You must be signed in to change notification settings - Fork 30.2k
Helpers update #7686
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
Helpers update #7686
Changes from 6 commits
9490618
242db1b
61f4612
73faefd
58fc304
2195fbb
64b6d08
e02e8c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,9 @@ export type NextPage<P = {}, IP = P> = { | |
| */ | ||
| export type PageConfig = { | ||
| amp?: boolean | 'hybrid' | ||
| api?: { | ||
| bodyParser?: boolean | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem with having a static export is that it always has to be configure by the user. Third party libraries can't configure the handlers they produce to opt out of this body-parser. e.g. if I create a proxy library, I'd have to ask my users to always include this static export: import someProxy from 'third-party';
export default someProxy();
// I'd have to ask users of my library to include the following or it won't work:
export const {
api: {
bodyParser: false
}
} |
||
| } | ||
| } | ||
|
|
||
| export { NextPageContext, NextComponentType, NextApiResponse, NextApiRequest } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| export const config = { | ||
| api: { | ||
| bodyParser: false | ||
| } | ||
| } | ||
|
|
||
| export default (req, res) => { | ||
| if (!req.body) { | ||
| let buffer = '' | ||
| req.on('data', chunk => { | ||
| buffer += chunk | ||
| }) | ||
|
|
||
| req.on('end', () => { | ||
| res.status(200).json(JSON.parse(Buffer.from(buffer).toString())) | ||
| }) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| export const config = { | ||
| api: { | ||
| bodyParser: true | ||
| } | ||
| } | ||
|
|
||
| export default (req, res) => { | ||
| if (req.body) { | ||
| res.status(200).json({ message: 'Parsed body' }) | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.