mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
This reverts `fb7c862` per @timneutkens - Removes the errors/*.md associated - Puts back `poweredByHeader` for `next.config.js` - Reincorporates test: X-Powered-By header ✓ should set it by default (3ms) ✓ should not set it when poweredByHeader==false (5ms) Also tested with `yarn link` and verified.
This commit is contained in:
parent
6ac25b02dc
commit
c92bc858f7
|
@ -1,15 +0,0 @@
|
||||||
# The poweredByHeader has been removed
|
|
||||||
|
|
||||||
#### Why This Error Occurred
|
|
||||||
|
|
||||||
Starting at Next.js version 5.0.0 the `poweredByHeader` option has been removed.
|
|
||||||
|
|
||||||
#### Possible Ways to Fix It
|
|
||||||
|
|
||||||
If you still want to remove `x-powered-by` you can use one of the custom-server examples.
|
|
||||||
|
|
||||||
And then manually remove the header using `res.removeHeader('x-powered-by')`
|
|
||||||
|
|
||||||
### Useful Links
|
|
||||||
|
|
||||||
- [Custom Server documentation + examples](https://github.com/zeit/next.js#custom-server-and-routing)
|
|
|
@ -5,6 +5,7 @@ const cache = new Map()
|
||||||
const defaultConfig = {
|
const defaultConfig = {
|
||||||
webpack: null,
|
webpack: null,
|
||||||
webpackDevMiddleware: null,
|
webpackDevMiddleware: null,
|
||||||
|
poweredByHeader: true,
|
||||||
distDir: '.next',
|
distDir: '.next',
|
||||||
assetPrefix: '',
|
assetPrefix: '',
|
||||||
configOrigin: 'default',
|
configOrigin: 'default',
|
||||||
|
@ -33,9 +34,6 @@ function loadConfig (dir, customConfig) {
|
||||||
if (path && path.length) {
|
if (path && path.length) {
|
||||||
const userConfigModule = require(path)
|
const userConfigModule = require(path)
|
||||||
userConfig = userConfigModule.default || userConfigModule
|
userConfig = userConfigModule.default || userConfigModule
|
||||||
if (userConfig.poweredByHeader === true || userConfig.poweredByHeader === false) {
|
|
||||||
console.warn('> the `poweredByHeader` option has been removed https://err.sh/zeit/next.js/powered-by-header-option-removed')
|
|
||||||
}
|
|
||||||
userConfig.configOrigin = 'next.config.js'
|
userConfig.configOrigin = 'next.config.js'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -323,7 +323,9 @@ export default class Server {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
res.setHeader('X-Powered-By', `Next.js ${pkg.version}`)
|
if (this.config.poweredByHeader) {
|
||||||
|
res.setHeader('X-Powered-By', `Next.js ${pkg.version}`)
|
||||||
|
}
|
||||||
return sendHTML(req, res, html, req.method, this.renderOpts)
|
return sendHTML(req, res, html, req.method, this.renderOpts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -134,6 +134,26 @@ describe('Production Usage', () => {
|
||||||
await app.render(req, res, req.url)
|
await app.render(req, res, req.url)
|
||||||
expect(headers['X-Powered-By']).toEqual(`Next.js ${pkg.version}`)
|
expect(headers['X-Powered-By']).toEqual(`Next.js ${pkg.version}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should not set it when poweredByHeader==false', async () => {
|
||||||
|
const req = { url: '/stateless', headers: {} }
|
||||||
|
const originalConfigValue = app.config.poweredByHeader
|
||||||
|
app.config.poweredByHeader = false
|
||||||
|
const res = {
|
||||||
|
getHeader () {
|
||||||
|
return false
|
||||||
|
},
|
||||||
|
setHeader (key, value) {
|
||||||
|
if (key === 'XPoweredBy') {
|
||||||
|
throw new Error('Should not set the XPoweredBy header')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
end () {}
|
||||||
|
}
|
||||||
|
|
||||||
|
await app.render(req, res, req.url)
|
||||||
|
app.config.poweredByHeader = originalConfigValue
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
dynamicImportTests(context, (p, q) => renderViaHTTP(context.appPort, p, q))
|
dynamicImportTests(context, (p, q) => renderViaHTTP(context.appPort, p, q))
|
||||||
|
|
Loading…
Reference in a new issue