Skip to content

Commit

Permalink
fix(emulator): Hosting emulator should not connect to 0.0.0.0 for emu…
Browse files Browse the repository at this point in the history
…lators (#3141)

* fix(emulator): Hosting emulator should not connect to 0.0.0.0 for emulators (#3121)

* Update CHANGELOG.md

Co-authored-by: Yuchen Shi <yuchenshi@google.com>
  • Loading branch information
lisp719 and yuchenshi committed Feb 16, 2021
1 parent ca9112e commit ea06936
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Fixes issue where proxied requests to dynamic content through the Hosting emulator would return unexpected `location` headers. (#3097)
- Fixes issue where optional extension parameters could not be omitted. (#3126)
- Fixes issue where deploying Cloud Functions for Firebase fails on Node.js v15. (#3120)
- Fixes issue where hosting emulator would connect to 0.0.0.0 for emulators. (#3121)
13 changes: 11 additions & 2 deletions src/hosting/implicitInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,17 @@ export async function implicitInit(options: any): Promise<TemplateServerResponse
const info = EmulatorRegistry.getInfo(e);

if (info) {
// IPv6 hosts need to be quoted using brackets.
const host = info.host.includes(":") ? `[${info.host}]` : info.host;
let host = info.host;

if (host === "0.0.0.0") {
host = "127.0.0.1";
} else if (host === "::") {
host = "[::1]";
} else if (host.includes(":")) {
// IPv6 hosts need to be quoted using brackets.
host = `[${host}]`;
}

emulators[e] = {
host,
port: info.port,
Expand Down

0 comments on commit ea06936

Please sign in to comment.