Skip to content

Fix console URL for RTDB commands #2801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 9, 2020
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
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