mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Use correct default for query (#5851)
This commit is contained in:
parent
6b7864e57e
commit
93424b64a9
|
@ -205,7 +205,7 @@ export default class Server {
|
||||||
return sendHTML(req, res, html, {generateEtags})
|
return sendHTML(req, res, html, {generateEtags})
|
||||||
}
|
}
|
||||||
|
|
||||||
public async render (req: IncomingMessage, res: ServerResponse, pathname: string, query: ParsedUrlQuery, parsedUrl: UrlWithParsedQuery): Promise<void> {
|
public async render (req: IncomingMessage, res: ServerResponse, pathname: string, query: ParsedUrlQuery = {}, parsedUrl?: UrlWithParsedQuery): Promise<void> {
|
||||||
const url: any = req.url
|
const url: any = req.url
|
||||||
if (isInternalUrl(url)) {
|
if (isInternalUrl(url)) {
|
||||||
return this.handleRequest(req, res, parsedUrl)
|
return this.handleRequest(req, res, parsedUrl)
|
||||||
|
@ -227,7 +227,7 @@ export default class Server {
|
||||||
return this.sendHTML(req, res, html)
|
return this.sendHTML(req, res, html)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async renderToHTML (req: IncomingMessage, res: ServerResponse, pathname: string, query: ParsedUrlQuery): Promise<string|null> {
|
public async renderToHTML (req: IncomingMessage, res: ServerResponse, pathname: string, query: ParsedUrlQuery = {}): Promise<string|null> {
|
||||||
try {
|
try {
|
||||||
// To make sure the try/catch is executed
|
// To make sure the try/catch is executed
|
||||||
const html = await renderToHTML(req, res, pathname, query, this.renderOpts)
|
const html = await renderToHTML(req, res, pathname, query, this.renderOpts)
|
||||||
|
@ -243,13 +243,13 @@ export default class Server {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async renderError (err: Error|null, req: IncomingMessage, res: ServerResponse, pathname: string, query: ParsedUrlQuery): Promise<void> {
|
public async renderError (err: Error|null, req: IncomingMessage, res: ServerResponse, pathname: string, query: ParsedUrlQuery = {}): Promise<void> {
|
||||||
res.setHeader('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate')
|
res.setHeader('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate')
|
||||||
const html = await this.renderErrorToHTML(err, req, res, pathname, query)
|
const html = await this.renderErrorToHTML(err, req, res, pathname, query)
|
||||||
return this.sendHTML(req, res, html)
|
return this.sendHTML(req, res, html)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async renderErrorToHTML (err: Error|null, req: IncomingMessage, res: ServerResponse, pathname: string, query: ParsedUrlQuery) {
|
public async renderErrorToHTML (err: Error|null, req: IncomingMessage, res: ServerResponse, pathname: string, query: ParsedUrlQuery = {}) {
|
||||||
return renderErrorToHTML(err, req, res, pathname, query, this.renderOpts)
|
return renderErrorToHTML(err, req, res, pathname, query, this.renderOpts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
test/integration/custom-server/pages/no-query.js
Normal file
1
test/integration/custom-server/pages/no-query.js
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export default () => 'test'
|
|
@ -10,6 +10,10 @@ const handleNextRequests = app.getRequestHandler()
|
||||||
|
|
||||||
app.prepare().then(() => {
|
app.prepare().then(() => {
|
||||||
const server = new http.Server((req, res) => {
|
const server = new http.Server((req, res) => {
|
||||||
|
if (req.url === '/no-query') {
|
||||||
|
return app.render(req, res, '/no-query')
|
||||||
|
}
|
||||||
|
|
||||||
if (/setAssetPrefix/.test(req.url)) {
|
if (/setAssetPrefix/.test(req.url)) {
|
||||||
app.setAssetPrefix(`http://127.0.0.1:${port}`)
|
app.setAssetPrefix(`http://127.0.0.1:${port}`)
|
||||||
} else if (/setEmptyAssetPrefix/.test(req.url)) {
|
} else if (/setEmptyAssetPrefix/.test(req.url)) {
|
||||||
|
|
|
@ -37,6 +37,10 @@ describe('Custom Server', () => {
|
||||||
beforeAll(() => startServer())
|
beforeAll(() => startServer())
|
||||||
afterAll(() => killApp(server))
|
afterAll(() => killApp(server))
|
||||||
|
|
||||||
|
it('should handle render with undefined query', async () => {
|
||||||
|
expect(await renderViaHTTP(appPort, '/no-query')).toMatch(/"query":/)
|
||||||
|
})
|
||||||
|
|
||||||
it('should set the assetPrefix dynamically', async () => {
|
it('should set the assetPrefix dynamically', async () => {
|
||||||
const normalUsage = await renderViaHTTP(appPort, '/asset')
|
const normalUsage = await renderViaHTTP(appPort, '/asset')
|
||||||
expect(normalUsage).not.toMatch(/127\.0\.0\.1/)
|
expect(normalUsage).not.toMatch(/127\.0\.0\.1/)
|
||||||
|
|
Loading…
Reference in a new issue