Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions spec/v1/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
8 changes: 8 additions & 0 deletions src/v1/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down