mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
### What? Fixes #61611 ### Why? Any one having custom server may be having logic to set cookies during GET requests too. Currently nextjs in app directory does not allow to do so but with custom server its very much possible. ### How? By merging cookies of redirect response and server action POSt response ### Tests I have added one more test to existing suite and it passing with fix in place.  ### Notes This bug is reproducible only if developer has custom server on top of next app but still very probable --------- Co-authored-by: Shu Ding <[email protected]> Co-authored-by: JJ Kasper <[email protected]>
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
const http = require('http')
|
|
const { parse } = require('url')
|
|
const next = require('next')
|
|
const getPort = require('get-port')
|
|
|
|
async function main() {
|
|
const dev = process.env.NEXT_TEST_MODE === 'dev'
|
|
process.env.NODE_ENV = dev ? 'development' : 'production'
|
|
|
|
const port = await getPort()
|
|
|
|
const app = next({ dev, port })
|
|
const handle = app.getRequestHandler()
|
|
|
|
await app.prepare()
|
|
|
|
const server = http.createServer(async (req, res) => {
|
|
try {
|
|
const parsedUrl = parse(req.url, true)
|
|
const { pathname } = parsedUrl
|
|
res.setHeader(
|
|
'set-cookie',
|
|
'custom-server-test-cookie=custom-server-test-cookie-val'
|
|
)
|
|
if (pathname.startsWith('/base')) {
|
|
await handle(req, res, parsedUrl)
|
|
} else {
|
|
res.end()
|
|
}
|
|
} catch (err) {
|
|
res.statusCode = 500
|
|
res.end('Internal Server Error')
|
|
}
|
|
})
|
|
|
|
server.once('error', (err) => {
|
|
console.error(err)
|
|
process.exit(1)
|
|
})
|
|
|
|
server.listen(port, () => {
|
|
console.log(`- Local: http://localhost:${port}`)
|
|
console.log(`- Next mode: ${dev ? 'development' : process.env.NODE_ENV}`)
|
|
})
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error(err)
|
|
process.exit(1)
|
|
})
|