Skip to content

Commit 0578967

Browse files
authored
Fix console URL for RTDB commands (#2801)
1 parent 7133c28 commit 0578967

File tree

5 files changed

+29
-9
lines changed

5 files changed

+29
-9
lines changed

src/commands/database-push.js

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ module.exports = new Command("database:push <path> [infile]")
6767

6868
var consoleUrl = utils.getDatabaseViewDataUrl(
6969
origin,
70+
options.project,
7071
options.instance,
7172
path + body.name
7273
);

src/commands/database-set.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ module.exports = new Command("database:set <path> [infile]")
8383
logger.info();
8484
logger.info(
8585
clc.bold("View data at:"),
86-
utils.getDatabaseViewDataUrl(origin, options.instance, path)
86+
utils.getDatabaseViewDataUrl(origin, options.project, options.instance, path)
8787
);
8888
return resolve();
8989
})

src/commands/database-update.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ module.exports = new Command("database:update <path> [infile]")
8181
logger.info();
8282
logger.info(
8383
clc.bold("View data at:"),
84-
utils.getDatabaseViewDataUrl(origin, options.project, path)
84+
utils.getDatabaseViewDataUrl(origin, options.project, options.instance, path)
8585
);
8686
return resolve();
8787
})

src/test/utils.spec.ts

+20-5
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,31 @@ describe("utils", () => {
110110
});
111111

112112
describe("getDatabaseViewDataUrl", () => {
113-
it("should get a view data url for prod", () => {
113+
it("should get a view data url for legacy prod URL", () => {
114114
expect(
115-
utils.getDatabaseViewDataUrl("https://firebaseio.com", "fir-proj", "/foo/bar")
116-
).to.equal("https://console.firebase.google.com/project/fir-proj/database/data/foo/bar");
115+
utils.getDatabaseViewDataUrl("https://firebaseio.com", "fir-proj", "fir-ns", "/foo/bar")
116+
).to.equal(
117+
"https://console.firebase.google.com/project/fir-proj/database/fir-ns/data/foo/bar"
118+
);
119+
});
120+
121+
it("should get a view data url for new prod URL", () => {
122+
expect(
123+
utils.getDatabaseViewDataUrl(
124+
"https://firebasedatabase.app",
125+
"fir-proj",
126+
"fir-ns",
127+
"/foo/bar"
128+
)
129+
).to.equal(
130+
"https://console.firebase.google.com/project/fir-proj/database/fir-ns/data/foo/bar"
131+
);
117132
});
118133

119134
it("should get a view data url for the emulator", () => {
120135
expect(
121-
utils.getDatabaseViewDataUrl("http://localhost:9000", "fir-proj", "/foo/bar")
122-
).to.equal("http://localhost:9000/foo/bar.json?ns=fir-proj");
136+
utils.getDatabaseViewDataUrl("http://localhost:9000", "fir-proj", "fir-ns", "/foo/bar")
137+
).to.equal("http://localhost:9000/foo/bar.json?ns=fir-ns");
123138
});
124139
});
125140

src/utils.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,16 @@ export function getDatabaseUrl(origin: string, namespace: string, pathname: stri
8383
*/
8484
export function getDatabaseViewDataUrl(
8585
origin: string,
86+
project: string,
8687
namespace: string,
8788
pathname: string
8889
): string {
8990
const urlObj = new url.URL(origin);
90-
if (urlObj.hostname.includes("firebaseio.com")) {
91-
return consoleUrl(namespace, "/database/data" + pathname);
91+
if (
92+
urlObj.hostname.includes("firebaseio.com") ||
93+
urlObj.hostname.includes("firebasedatabase.app")
94+
) {
95+
return consoleUrl(project, `/database/${namespace}/data${pathname}`);
9296
} else {
9397
// TODO(samstern): View in Emulator UI
9498
return getDatabaseUrl(origin, namespace, pathname + ".json");

0 commit comments

Comments
 (0)