Files
next.js/test/integration/api-support/pages/api/proxy-self.js
Niklas MischkulnigandGitHub 1c1550ca7b tests: Assert dpl query string in all tests for Turbopack (#90592)
Enable skew protection for all start-mode tests when Turbopack is enabled (i.e. not dev). This works by setting `NEXT_DEPLOYMENT_ID` in the test infra

- When running the tests, `packages/next/src/server/lib/router-utils/resolve-routes.ts` now validates that all static asset requests have the correct `?dpl=...` query param value, and returns a 404 if missing.
- It can be disabled with `disableAutoSkewProtection: true` in the test options
- There were various tests that were asserting URLs and were missing the optional `?dpl` at the end.
   - `next.getDeploymentIdQuery()` can be used to get the `?dpl=dpl_123912js` string (or an empty string)
   - `next.getAssetQuery()` currently behaves like `getDeploymentIdQuery`, but will switch to prefer the immutable static token in #88607
2026-02-27 10:06:14 +01:00

22 lines
635 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
? process.env.NEXT_DEPLOYMENT_ID
? `_next/static/${req.query.buildId}/_ssgManifest.js?dpl=${process.env.NEXT_DEPLOYMENT_ID}`
: `_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)
})
}