diff --git a/spec/v1/config.spec.ts b/spec/v1/config.spec.ts index d1deea4fd..7b750032d 100644 --- a/spec/v1/config.spec.ts +++ b/spec/v1/config.spec.ts @@ -47,6 +47,23 @@ describe('config()', () => { (config as any).firebaseConfigCache = null; delete process.env.FIREBASE_CONFIG; delete process.env.CLOUD_RUNTIME_CONFIG; + delete process.env.K_CONFIGURATION; + }); + + it('will never load in GCFv2', () => { + const json = JSON.stringify({ + foo: 'bar', + firebase: {}, + }); + readFileSync + .withArgs('/srv/.runtimeconfig.json') + .returns(Buffer.from(json)); + + process.env.K_CONFIGURATION = 'my-service'; + expect(() => config.config()).to.throw( + Error, + /transition to using environment variables/ + ); }); it('loads config values from .runtimeconfig.json', () => { diff --git a/src/v1/config.ts b/src/v1/config.ts index f0793957d..01ca3a4cc 100644 --- a/src/v1/config.ts +++ b/src/v1/config.ts @@ -26,6 +26,14 @@ import * as path from 'path'; import * as firebase from 'firebase-admin'; export function config(): config.Config { + // K_CONFIGURATION is only set in GCFv2 + if (process.env.K_CONFIGURATION) { + throw new Error( + 'functions.config() is no longer available in Cloud Functions for ' + + 'Firebase v2. Please see the latest documentation for information ' + + 'on how to transition to using environment variables' + ); + } if (typeof config.singleton === 'undefined') { init(); }