1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

[refactor] poweredByHeader (#3716) (#3807)

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:
Jerome Fitzgerald 2018-02-14 12:02:48 -05:00 committed by Tim Neutkens
parent 6ac25b02dc
commit c92bc858f7
4 changed files with 24 additions and 19 deletions

View file

@ -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)

View file

@ -5,6 +5,7 @@ const cache = new Map()
const defaultConfig = {
webpack: null,
webpackDevMiddleware: null,
poweredByHeader: true,
distDir: '.next',
assetPrefix: '',
configOrigin: 'default',
@ -33,9 +34,6 @@ function loadConfig (dir, customConfig) {
if (path && path.length) {
const userConfigModule = require(path)
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'
}

View file

@ -323,7 +323,9 @@ export default class Server {
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)
}

View file

@ -134,6 +134,26 @@ describe('Production Usage', () => {
await app.render(req, res, req.url)
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))