-
Notifications
You must be signed in to change notification settings - Fork 67
Expose event and context of Netlify Function in Next.js pages and API routes #119
Conversation
This object is not needed on Netlify. It is a relict of next-aws-lambda.
When a page is being SSR-ed by a Netlify Function, allow users to access the function's event and context parameters. These can be accessed as a property on the `req` object in all SSR-ed pages and in API routes: - req.netlifyFunction.event - req.netlifyFunction.context This allows users to access/leverage Netlify identity for their Next.js page. See: #20 It also allows users to modify the callbackWaitsForEmptyEventLoop behavior. See: #66 (comment))
Test that users can modify the Netlify Function's callbackWaitsForEmptyEventLoop behavior via the newly exposed function event and context objects. When callbackWaitsForEmptyEventLoop is true (default), the function does not finish until all async processes and timeouts are completed (or cleared). The user can set this to false to not wait for other processes to finish.
@lindsaylevine @ehmicky: Is I opted for |
PS: Why make the
req (or res ) object and they will be available to users.
|
Add instructions, details, and an example for using Netlify Identity with next-on-netlify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
THIS IS SO DOPE, YAY
``` | ||
|
||
\* Note that pages using getInitialProps are only server-side rendered on initial page load and not when the user navigates client-side between pages. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AWESOMEEEE
lib/templates/createRequestObject.js
Outdated
// It also allows users to change the behavior of waiting for empty event | ||
// loop. | ||
// See: https://github.com/netlify/next-on-netlify/issues/66#issuecomment-719988804 | ||
req.netlifyFunction = { event, context }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this name is fine. maybe netlifyFunctionData since the value itself is not really a function but 🤷♀️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True! How about netlifyFunctionParams
, since it's not just data but also some functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good!!!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's now netlifyFunctionParams
:)
Expose event and context of Netlify Function in Next.js pages and API routes as `netlifyFunctionParams` (rather than `netlifyFunction`). The new name is clearer, since we're just making the parameters of the function available and not the function itself.
If we're happy with |
do it!!! |
- Support for i18n in Next 10 ([#75](#75)) - dependabot: node-notifier from 8.0.0 to 8.0.1 ([#125](#125)) - Expose Netlify function params as netlifyFunctionParams ([#119](#119)) - Fix: local cypress cache control ([#118](#118)) - Fix: add res.finished to createResponseObject ([#117](#117)) - Fix: Windows support ([#101](#101)) - Improve logs for specified functions/publish dirs ([#100](#100))
When a page is being SSR-ed by a Netlify Function, allow users to access the function's event and context parameters. These can be accessed as a property on the
req
object in all SSR-ed pages and in API routes:Example
Use Cases
This allows users to access/leverage Netlify identity for their Next.js page (see #20).
It also allows users to modify the callbackWaitsForEmptyEventLoop behavior (see #66 (comment)).
Fixes #20