Skip to content
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

Extend IncomingMessage type to include cookies from middleware #19724

Merged
merged 14 commits into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/next/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ export type GetStaticPaths<P extends ParsedUrlQuery = ParsedUrlQuery> = (
export type GetServerSidePropsContext<
Q extends ParsedUrlQuery = ParsedUrlQuery
> = {
req: IncomingMessage
req: IncomingMessage & {
cookies?: { [key: string]: any }
}
res: ServerResponse
params?: Q
query: ParsedUrlQuery
Expand Down
18 changes: 18 additions & 0 deletions test/integration/typescript/pages/ssr/cookies.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { GetServerSideProps } from 'next'

type Props = {
data: string
cookies: any
}

export const getServerSideProps: GetServerSideProps<Props> = async ({
req,
}) => {
return {
props: { data: 'hello world', cookies: req.cookies },
}
}

export default function Page({ cookies }: Props) {
return <pre id="cookies">{JSON.stringify(cookies)}</pre>
}
5 changes: 5 additions & 0 deletions test/integration/typescript/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ describe('TypeScript Features', () => {
expect($('body').text()).toMatch(/1000000000000/)
})

it('should render the cookies page', async () => {
const $ = await get$('/ssr/cookies')
expect($('#cookies').text()).toBe('{}')
})

it('should resolve files in correct order', async () => {
const $ = await get$('/hello')
expect($('#imported-value').text()).toBe('OK')
Expand Down