From 1a4385ba1bccc097a404bcdd08e0d56eb3265213 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Mon, 3 Feb 2020 16:34:23 -0600 Subject: [PATCH] =?UTF-8?q?Make=20sure=20runtime=20config=20works=20in=20d?= =?UTF-8?q?ev=20mode=20for=20serverless=20targ=E2=80=A6=20(#10402)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/next-server/server/next-server.ts | 10 ++-- .../test/index.test.js | 59 +++++++++++++------ 2 files changed, 45 insertions(+), 24 deletions(-) diff --git a/packages/next/next-server/server/next-server.ts b/packages/next/next-server/server/next-server.ts index a67d149c04a3bea..9f963061ada1228 100644 --- a/packages/next/next-server/server/next-server.ts +++ b/packages/next/next-server/server/next-server.ts @@ -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, diff --git a/test/integration/serverless-runtime-configs/test/index.test.js b/test/integration/serverless-runtime-configs/test/index.test.js index b9776f2055ed230..648ff080b076ca8 100644 --- a/test/integration/serverless-runtime-configs/test/index.test.js +++ b/test/integration/serverless-runtime-configs/test/index.test.js @@ -6,6 +6,7 @@ import { nextBuild, findPort, killApp, + launchApp, renderViaHTTP, initNextServerScript, } from 'next-test-utils' @@ -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`) @@ -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) }) })