Unverified Commit 2f26fb44 authored by Vitor Balocco's avatar Vitor Balocco Committed by GitHub

Update getServerSideProps docs with req.cookie note (#29457)



## Documentation / Examples

Add a note to the `getServerSideProps` docs that `context.req` [contains](https://github.com/vercel/next.js/blob/c27e3a41dcf9590fb1c9ba9b9e16517cf4cb49b4/packages/next/types/index.d.ts#L148-L150) a `context.req.cookies` attribute.

I based the copy off of the one from https://nextjs.org/docs/api-routes/api-middlewares.

Checklist:
- [x] Make sure the linting passes
parent 59b6967e
...@@ -660,7 +660,7 @@ export async function getServerSideProps(context) { ...@@ -660,7 +660,7 @@ export async function getServerSideProps(context) {
The `context` parameter is an object containing the following keys: The `context` parameter is an object containing the following keys:
- `params`: If this page uses a dynamic route, `params` contains the route parameters. If the page name is `[id].js` , then `params` will look like `{ id: ... }`. To learn more, take a look at the [Dynamic Routing documentation](/docs/routing/dynamic-routes.md). - `params`: If this page uses a dynamic route, `params` contains the route parameters. If the page name is `[id].js` , then `params` will look like `{ id: ... }`. To learn more, take a look at the [Dynamic Routing documentation](/docs/routing/dynamic-routes.md).
- `req`: [The HTTP IncomingMessage object](https://nodejs.org/api/http.html#http_class_http_incomingmessage). - `req`: [The HTTP IncomingMessage object](https://nodejs.org/api/http.html#http_class_http_incomingmessage), plus additional [built-in parsing helpers](#provided-req-middleware-in-getserversideprops).
- `res`: [The HTTP response object](https://nodejs.org/api/http.html#http_class_http_serverresponse). - `res`: [The HTTP response object](https://nodejs.org/api/http.html#http_class_http_serverresponse).
- `query`: An object representing the query string. - `query`: An object representing the query string.
- `preview`: `preview` is `true` if the page is in the preview mode and `false` otherwise. See the [Preview Mode documentation](/docs/advanced-features/preview-mode.md). - `preview`: `preview` is `true` if the page is in the preview mode and `false` otherwise. See the [Preview Mode documentation](/docs/advanced-features/preview-mode.md).
...@@ -727,6 +727,12 @@ The `context` parameter is an object containing the following keys: ...@@ -727,6 +727,12 @@ The `context` parameter is an object containing the following keys:
> >
> Fetching from an external API is fine! > Fetching from an external API is fine!
### Provided `req` middleware in `getServerSideProps`
The `req` in the context passed to `getServerSideProps` provides built in middleware that parses the incoming request (req). That middleware is:
- `req.cookies` - An object containing the cookies sent by the request. Defaults to `{}`
### Example ### Example
Here’s an example which uses `getServerSideProps` to fetch data at request time and pre-renders it. This example is also in the [Pages documentation](/docs/basic-features/pages.md). Here’s an example which uses `getServerSideProps` to fetch data at request time and pre-renders it. This example is also in the [Pages documentation](/docs/basic-features/pages.md).
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment