Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fix console URL for RTDB commands
  • Loading branch information
sarajmunjal committed Nov 9, 2020
commit 04886658347ca7240750a167de999a4d145e9e98
1 change: 1 addition & 0 deletions src/commands/database-push.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ module.exports = new Command("database:push <path> [infile]")

var consoleUrl = utils.getDatabaseViewDataUrl(
origin,
options.project,
options.instance,
path + body.name
);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/database-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ module.exports = new Command("database:set <path> [infile]")
logger.info();
logger.info(
clc.bold("View data at:"),
utils.getDatabaseViewDataUrl(origin, options.instance, path)
utils.getDatabaseViewDataUrl(origin, options.project, options.instance, path)
);
return resolve();
})
Expand Down
2 changes: 1 addition & 1 deletion src/commands/database-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module.exports = new Command("database:update <path> [infile]")
logger.info();
logger.info(
clc.bold("View data at:"),
utils.getDatabaseViewDataUrl(origin, options.project, path)
utils.getDatabaseViewDataUrl(origin, options.project, options.instance, path)
);
return resolve();
})
Expand Down
25 changes: 20 additions & 5 deletions src/test/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,31 @@ describe("utils", () => {
});

describe("getDatabaseViewDataUrl", () => {
it("should get a view data url for prod", () => {
it("should get a view data url for legacy prod URL", () => {
expect(
utils.getDatabaseViewDataUrl("https://firebaseio.com", "fir-proj", "/foo/bar")
).to.equal("https://console.firebase.google.com/project/fir-proj/database/data/foo/bar");
utils.getDatabaseViewDataUrl("https://firebaseio.com", "fir-proj", "fir-ns", "/foo/bar")
).to.equal(
"https://console.firebase.google.com/project/fir-proj/database/fir-ns/data/foo/bar"
);
});

it("should get a view data url for new prod URL", () => {
expect(
utils.getDatabaseViewDataUrl(
"https://firebasedatabase.app",
"fir-proj",
"fir-ns",
"/foo/bar"
)
).to.equal(
"https://console.firebase.google.com/project/fir-proj/database/fir-ns/data/foo/bar"
);
});

it("should get a view data url for the emulator", () => {
expect(
utils.getDatabaseViewDataUrl("http://localhost:9000", "fir-proj", "/foo/bar")
).to.equal("http://localhost:9000/foo/bar.json?ns=fir-proj");
utils.getDatabaseViewDataUrl("http://localhost:9000", "fir-proj", "fir-ns", "/foo/bar")
).to.equal("http://localhost:9000/foo/bar.json?ns=fir-ns");
});
});

Expand Down
8 changes: 6 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,16 @@ export function getDatabaseUrl(origin: string, namespace: string, pathname: stri
*/
export function getDatabaseViewDataUrl(
origin: string,
project: string,
namespace: string,
pathname: string
): string {
const urlObj = new url.URL(origin);
if (urlObj.hostname.includes("firebaseio.com")) {
return consoleUrl(namespace, "/database/data" + pathname);
if (
urlObj.hostname.includes("firebaseio.com") ||
urlObj.hostname.includes("firebasedatabase.app")
) {
return consoleUrl(project, `/database/${namespace}/data${pathname}`);
} else {
// TODO(samstern): View in Emulator UI
return getDatabaseUrl(origin, namespace, pathname + ".json");
Expand Down