mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
This ensures we don't pass along original headers when an API route is proxying back to the dev server. x-ref: [slack thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1681231721085539)
20 lines
490 B
JavaScript
20 lines
490 B
JavaScript
import httpProxy from 'http-proxy'
|
|
|
|
export default async function handler(req, res) {
|
|
const port = req.headers.host.split(':').pop()
|
|
const proxy = httpProxy.createProxy({
|
|
target: `http://127.0.0.1:${port}/${
|
|
req.query.buildId
|
|
? `_next/static/${req.query.buildId}/_ssgManifest.js`
|
|
: `user`
|
|
}`,
|
|
ignorePath: true,
|
|
})
|
|
|
|
await new Promise((resolve, reject) => {
|
|
proxy.on('error', reject)
|
|
proxy.on('close', resolve)
|
|
proxy.web(req, res)
|
|
})
|
|
}
|