Unverified Commit 1a53ca74 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Add x-powered-by (#7029)

* Add x-powered-by

* Remove ampEnabled type
parent e4ceb903
......@@ -21,7 +21,5 @@ app.prepare()
handle(req, res, parsedUrl)
}
})
.listen(port, () => {
console.log(`> Ready on http://localhost:${port}`)
})
.listen(port)
})
......@@ -16,6 +16,7 @@ const defaultConfig = {
generateEtags: true,
pageExtensions: ['jsx', 'js'],
target: 'server',
poweredByHeader: true,
onDemandEntries: {
maxInactiveAge: 60 * 1000,
pagesBufferLength: 2
......
......@@ -28,8 +28,6 @@ type ServerConstructor = {
conf?: NextConfig,
}
const ENDING_IN_JSON_REGEX = /\.json$/
export default class Server {
dir: string
quiet: boolean
......@@ -37,6 +35,7 @@ export default class Server {
distDir: string
buildId: string
renderOpts: {
poweredByHeader: boolean
noDirtyAmp: boolean
ampBindInitData: boolean
staticMarkup: boolean
......@@ -78,6 +77,7 @@ export default class Server {
this.renderOpts = {
noDirtyAmp: this.nextConfig.experimental.noDirtyAmp,
ampBindInitData: this.nextConfig.experimental.ampBindInitData,
poweredByHeader: this.nextConfig.poweredByHeader,
staticMarkup,
buildId: this.buildId,
generateEtags,
......@@ -248,8 +248,8 @@ export default class Server {
res: ServerResponse,
html: string,
) {
const { generateEtags } = this.renderOpts
return sendHTML(req, res, html, { generateEtags })
const { generateEtags, poweredByHeader } = this.renderOpts
return sendHTML(req, res, html, { generateEtags, poweredByHeader })
}
public async render(
......
......@@ -3,10 +3,14 @@ import generateETag from 'etag'
import fresh from 'fresh'
import { isResSent } from '../lib/utils'
export function sendHTML(req: IncomingMessage, res: ServerResponse, html: string, { generateEtags }: {generateEtags: boolean}) {
export function sendHTML(req: IncomingMessage, res: ServerResponse, html: string, { generateEtags, poweredByHeader }: {generateEtags: boolean, poweredByHeader: boolean}) {
if (isResSent(res)) return
const etag = generateEtags ? generateETag(html) : undefined
if (poweredByHeader) {
res.setHeader('X-Powered-By', 'Next.js')
}
if (fresh(req.headers, { etag })) {
res.statusCode = 304
res.end()
......
......@@ -7,6 +7,7 @@ module.exports = withCSS(withSass({
// Make sure entries are not getting disposed.
maxInactiveAge: 1000 * 60 * 60
},
poweredByHeader: false,
cssModules: true,
serverRuntimeConfig: {
mySecret: 'secret'
......
......@@ -8,6 +8,7 @@ import {
launchApp,
killApp
} from 'next-test-utils'
import fetch from 'node-fetch'
// test suits
import rendering from './rendering'
......@@ -29,6 +30,13 @@ describe('Configuration', () => {
renderViaHTTP(context.appPort, '/module-only-component')
])
})
it('should disable X-Powered-By header support', async () => {
const url = `http://localhost:${context.appPort}/`
const header = (await fetch(url)).headers.get('X-Powered-By')
expect(header).not.toBe('Next.js')
})
afterAll(() => {
killApp(context.server)
})
......
......@@ -55,6 +55,13 @@ describe('Production Usage', () => {
expect(res2.status).toBe(304)
})
it('should have X-Powered-By header support', async () => {
const url = `http://localhost:${appPort}/`
const header = (await fetch(url)).headers.get('X-Powered-By')
expect(header).toBe('Next.js')
})
it('should render 404 for routes that do not exist', async () => {
const url = `http://localhost:${appPort}/abcdefghijklmno`
const res = await fetch(url)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment