Skip to content

Commit

Permalink
Make sure runtime config works in dev mode for serverless targ… (verc…
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk authored and chibicode committed Feb 11, 2020
1 parent 9f3da3d commit 1a4385b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 24 deletions.
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)
})
})

0 comments on commit 1a4385b

Please sign in to comment.