Unverified Commit 7641278f authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Fix port value for metadataBase (#49924)

metadataBase is using `process.env.PORT` to construct a host when there's no `metadataBase` specified in layout. Dev server needs to pass down the PORT env from the parent prcoess.

Fixes #49807
Fixes #49859
Closes #49889
parent 4970811c
...@@ -187,6 +187,7 @@ export async function startServer({ ...@@ -187,6 +187,7 @@ export async function startServer({
env: { env: {
FORCE_COLOR: '1', FORCE_COLOR: '1',
...((initialEnv || process.env) as typeof process.env), ...((initialEnv || process.env) as typeof process.env),
PORT: port + '',
NODE_OPTIONS: getNodeOptionsWithoutInspect().trim(), NODE_OPTIONS: getNodeOptionsWithoutInspect().trim(),
}, },
}, },
......
...@@ -18,8 +18,9 @@ describe('Project Directory Renaming', () => { ...@@ -18,8 +18,9 @@ describe('Project Directory Renaming', () => {
`, `,
}, },
skipStart: true, skipStart: true,
forcedPort: (await findPort()) + '',
}) })
next.forcedPort = (await findPort()) + ''
await next.start() await next.start()
}) })
afterAll(() => next.destroy()) afterAll(() => next.destroy())
......
import { createNext, FileRef } from 'e2e-utils' import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base' import { NextInstance } from 'test/lib/next-modes/base'
import { fetchViaHTTP } from 'next-test-utils' import { fetchViaHTTP, findPort } from 'next-test-utils'
describe('app dir - metadata missing metadataBase', () => { describe('app dir - metadata missing metadataBase', () => {
let next: NextInstance let next: NextInstance
let port: number
if ((global as any).isNextDeploy) { if ((global as any).isNextDeploy) {
return it('should skip for deploy', () => {}) return it('should skip for deploy', () => {})
} }
beforeAll(async () => { beforeAll(async () => {
port = await findPort()
next = await createNext({ next = await createNext({
skipStart: true, skipStart: true,
files: new FileRef(__dirname), files: new FileRef(__dirname),
forcedPort: port + '',
}) })
}) })
afterAll(() => next.destroy()) afterAll(() => next.destroy())
...@@ -23,7 +26,7 @@ describe('app dir - metadata missing metadataBase', () => { ...@@ -23,7 +26,7 @@ describe('app dir - metadata missing metadataBase', () => {
expect(next.cliOutput).toInclude( expect(next.cliOutput).toInclude(
'metadata.metadataBase is not set for resolving social open graph or twitter images, fallbacks to' 'metadata.metadataBase is not set for resolving social open graph or twitter images, fallbacks to'
) )
expect(next.cliOutput).toInclude('"http://localhost:') expect(next.cliOutput).toInclude(`"http://localhost:${port}`)
expect(next.cliOutput).toInclude( expect(next.cliOutput).toInclude(
'. See https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadatabase' '. See https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadatabase'
) )
......
...@@ -32,6 +32,7 @@ export interface NextInstanceOpts { ...@@ -32,6 +32,7 @@ export interface NextInstanceOpts {
env?: Record<string, string> env?: Record<string, string>
dirSuffix?: string dirSuffix?: string
turbo?: boolean turbo?: boolean
forcedPort?: string
} }
/** /**
......
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