Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure runtime config works in dev mode for serverless target #10402

Merged
merged 1 commit into from Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions packages/next/next-server/server/next-server.ts
Expand Up @@ -163,12 +163,10 @@ export default class Server {
}

// Initialize next/config with the environment configuration
if (this.nextConfig.target === 'server') {
envConfig.setConfig({
serverRuntimeConfig,
publicRuntimeConfig,
})
}
envConfig.setConfig({
serverRuntimeConfig,
publicRuntimeConfig,
})

this.serverBuildDir = join(
this.distDir,
Expand Down
59 changes: 41 additions & 18 deletions test/integration/serverless-runtime-configs/test/index.test.js
Expand Up @@ -6,6 +6,7 @@ import {
nextBuild,
findPort,
killApp,
launchApp,
renderViaHTTP,
initNextServerScript,
} from 'next-test-utils'
Expand Down Expand Up @@ -74,24 +75,7 @@ describe('Serverless runtime configs', () => {
)
})

it('should support runtime configs in serverless mode', 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)

const testRuntimeConfig = async (app, appPort) => {
const browser = await webdriver(appPort, '/config')

const clientHTML = await browser.eval(`document.documentElement.innerHTML`)
Expand Down Expand Up @@ -140,5 +124,44 @@ describe('Serverless runtime configs', () => {
expect(JSON.parse(docClientConfig)).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)
})
})