Unverified Commit 89b2dfc5 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Make sure runtime config works in dev mode for serverless targ… (#10402)

parent c480c37c
...@@ -163,12 +163,10 @@ export default class Server { ...@@ -163,12 +163,10 @@ export default class Server {
} }
// Initialize next/config with the environment configuration // Initialize next/config with the environment configuration
if (this.nextConfig.target === 'server') { envConfig.setConfig({
envConfig.setConfig({ serverRuntimeConfig,
serverRuntimeConfig, publicRuntimeConfig,
publicRuntimeConfig, })
})
}
this.serverBuildDir = join( this.serverBuildDir = join(
this.distDir, this.distDir,
......
...@@ -6,6 +6,7 @@ import { ...@@ -6,6 +6,7 @@ import {
nextBuild, nextBuild,
findPort, findPort,
killApp, killApp,
launchApp,
renderViaHTTP, renderViaHTTP,
initNextServerScript, initNextServerScript,
} from 'next-test-utils' } from 'next-test-utils'
...@@ -74,24 +75,7 @@ describe('Serverless runtime configs', () => { ...@@ -74,24 +75,7 @@ describe('Serverless runtime configs', () => {
) )
}) })
it('should support runtime configs in serverless mode', async () => { const testRuntimeConfig = async (app, appPort) => {
await fs.writeFile(
nextConfigPath,
`module.exports = {
target: 'serverless',
serverRuntimeConfig: {
hello: 'world'
},
publicRuntimeConfig: {
another: 'thing'
}
}`
)
await nextBuild(appDir, [], { stderr: true, stdout: true })
const appPort = await findPort()
const app = await nextStart(appDir, appPort)
const browser = await webdriver(appPort, '/config') const browser = await webdriver(appPort, '/config')
const clientHTML = await browser.eval(`document.documentElement.innerHTML`) const clientHTML = await browser.eval(`document.documentElement.innerHTML`)
...@@ -140,5 +124,44 @@ describe('Serverless runtime configs', () => { ...@@ -140,5 +124,44 @@ describe('Serverless runtime configs', () => {
expect(JSON.parse(docClientConfig)).toEqual(expectedSsrConfig) expect(JSON.parse(docClientConfig)).toEqual(expectedSsrConfig)
expect(JSON.parse(apiJson)).toEqual(expectedSsrConfig) expect(JSON.parse(apiJson)).toEqual(expectedSsrConfig)
}
it('should support runtime configs in serverless mode (production)', async () => {
await fs.writeFile(
nextConfigPath,
`module.exports = {
target: 'serverless',
serverRuntimeConfig: {
hello: 'world'
},
publicRuntimeConfig: {
another: 'thing'
}
}`
)
await nextBuild(appDir, [], { stderr: true, stdout: true })
const appPort = await findPort()
const app = await nextStart(appDir, appPort)
await testRuntimeConfig(app, appPort)
})
it('should support runtime configs in serverless mode (dev)', async () => {
await fs.writeFile(
nextConfigPath,
`module.exports = {
target: 'serverless',
serverRuntimeConfig: {
hello: 'world'
},
publicRuntimeConfig: {
another: 'thing'
}
}`
)
const appPort = await findPort()
const app = await launchApp(appDir, appPort)
await testRuntimeConfig(app, appPort)
}) })
}) })
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