Unverified Commit a623653e authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Forward response to edge runtime for response modification (#49145)

For edge runtime, we're modifying `res.statusCode` in actions handler, but we didn't forward the `res` object to it, previously we're using a fake `res` `{}`. This PR fixes it so that the propery status code will be returned to the client

[slack-thread](https://vercel.slack.com/archives/C052S77L05C/p1682988777740609)
parent c5468474
......@@ -361,7 +361,7 @@ export default class NextWebServer extends BaseServer<WebServerOptions> {
protected async renderHTML(
req: WebNextRequest,
_res: WebNextResponse,
res: WebNextResponse,
pathname: string,
query: NextParsedUrlQuery,
renderOpts: RenderOpts
......@@ -379,7 +379,7 @@ export default class NextWebServer extends BaseServer<WebServerOptions> {
headers: req.headers,
body: req.body,
} as any,
{} as any,
res as any,
pathname,
query,
Object.assign(renderOpts, {
......
......@@ -199,6 +199,18 @@ createNextDescribe(
await browser.elementByCss('#dec').click()
await check(() => browser.elementByCss('h1').text(), '3')
})
it('should return error response for hoc auth wrappers in edge runtime', async () => {
const browser = await next.browser('/header/edge')
await await browser.eval(`document.cookie = 'auth=0'`)
await browser.elementByCss('#authed').click()
await check(async () => {
const text = await browser.elementByCss('h1').text()
console.log('text', text)
return text && text.length > 0 ? text : 'failed'
}, /Multipart form data is not supported/)
})
})
}
)
import { getCookie, getHeader, setCookie } from '../actions'
import UI from '../ui'
import { validator } from '../validator'
export default function Page() {
const prefix = 'Prefix:'
return (
<UI
getCookie={getCookie}
getHeader={getHeader}
setCookie={setCookie}
getAuthedUppercase={validator(async (str) => {
'use server'
return prefix + ' ' + str.toUpperCase()
})}
/>
)
}
export const runtime = 'edge'
import UI from './ui'
import { getCookie, getHeader, setCookie } from './actions'
import UI from './ui'
import { validator } from './validator'
export default function Page() {
......
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